目录

moonbit-cbor

A high-performance, standard-compliant CBOR (Concise Binary Object Representation, RFC 8949) serialization and deserialization library for MoonBit.

Features

  • Full RFC 8949 Support: Supports integers, byte strings, text strings, arrays, maps, semantic tags, and floating-point/simple values.
  • High Performance: Zero-allocation streaming encoder and low-overhead offset-based decoder.
  • Diagnostic Notation: Includes a printer for generating human-readable CBOR Diagnostic Notation (RFC 8949 Section 8).
  • Extensible: Trait-based polymorphic encoding (CborEncode) and decoding (CborDecode).
  • No Dependencies: Written purely in MoonBit, compatible with all targets (Wasm, Wasm-GC, JS, Native).

Quick Start

import "username/cbor"

fn main {
  // 1. Construct a CBOR AST
  let map : Array[(cbor.CborValue, cbor.CborValue)] = [
    (cbor.Text("hello"), cbor.Integer(42L)),
    (cbor.Text("world"), cbor.Array([cbor.Integer(1L), cbor.Integer(2L)])),
  ]
  let value = cbor.Map(map)

  // 2. Encode to bytes
  let bytes = cbor.encode(value)

  // 3. Decode back to AST
  match try? cbor.decode(bytes) {
    Ok(decoded) => println(cbor.diagnostic(decoded))
    Err(e) => println("Error: \{e}")
  }
}

Building & Testing

moon check
moon test

License

Apache-2.0 License

关于

本项目将从零开始在 MoonBit 中实现一个符合 RFC 8949 标准的高性能 CBOR (Concise Binary Object Representation) 序列化与反序列化库。 CBOR 是一种二进制数据序列化格式,旨在保持较小消息体积的同时,具备极低的代码复杂度与高扩展性(无需进行版本协商)。它在 WebAssembly (Wasm) 生态、物联网、边缘计算以及网络协议(如 C

49.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号