SBE binary message codecs and MoonBit code generation with reference interoperability tests
moon update
moon test --target js --warn-list=-implicit_impl_as_method --deny-warn
moon run cmd/main --target js --warn-list=-implicit_impl_as_method -- schema interop/upstream/example-schema.xml
moon run cmd/main --target js --warn-list=-implicit_impl_as_method -- encode interop/upstream/example-schema.xml 1 examples/car.json car.bin
moon run cmd/main --target js --warn-list=-implicit_impl_as_method -- decode interop/upstream/example-schema.xml car.binmoon run cmd/main --target js --warn-list=-implicit_impl_as_method -- generate interop/upstream/example-schema.xml generated/car/messages.mbt
moon fmt generated/car
moon check --target js --warn-list=-implicit_impl_as_method --deny-warnimport {
"liyun6666/moonsbe/generated/car" @car,
}moon run tools/interop.mbtxlet view = @car.Car::view(bytes)
let serial_number = view.f_serial_number()
let first_number = view.f_some_numbers(0)| 接口 | 用途 |
|---|---|
| parse_schema(xml, includes=...) | 编译 XML Schema,解析类型、布局和显式提供的 XInclude |
| value_from_json(schema, template_id, source) | 根据 Schema 读取消息 JSON,保留整数精度并拒绝重复键 |
| encode(schema, template_id, value, version=...) | 按 Schema 指定的头部布局编码一条完整消息 |
| decode(schema, bytes, max_entries=...) | 解码一条已有边界的完整消息,检查长度与资源上限 |
| generate_moonbit(xml, includes=...) | 生成类型化适配器与定长数值字段视图 |
| compare_schemas(old, newer) | 检查此运行时下的双向版本兼容风险 |
schema SCHEMA.xml
encode SCHEMA.xml TEMPLATE_ID MESSAGE.json OUTPUT.bin
decode SCHEMA.xml INPUT.bin [OUTPUT.json]
generate SCHEMA.xml OUTPUT.mbt
compare OLD_SCHEMA.xml NEW_SCHEMA.xml
hex INPUT.binmoon fmt --check
moon check --target js --warn-list=-implicit_impl_as_method --deny-warn
moon test --target js --warn-list=-implicit_impl_as_method --deny-warn
moon test --target wasm-gc -p liyun6666/moonsbe -p liyun6666/moonsbe/examples/extended --warn-list=-implicit_impl_as_method --deny-warn
moon run tools/interop.mbtx
moon run tools/stats.mbtxpub suberror SbeError {
InvalidSchema(String, Int)
Unsupported(String)
Truncated(Int, Int, Int)
InvalidValue(String, String)
InvalidMessage(String)
LimitExceeded(String)
} derive(Debug)pub(all) struct CompositeMember {
name : String
type_name : String
offset : Int
since_version : Int
} derive(Debug)pub(all) struct EvolutionReport {
old_version : Int
new_version : Int
old_reads_new : Bool
new_reads_old : Bool
differences : Array[SchemaDifference]
} derive(Debug, ToJson)fn FixedBlock::new(bytes : Bytes, start : Int, length : Int, order : ByteOrder) -> FixedBlock raise SbeErrorpub(all) struct GroupDef {
name : String
id : Int
since_version : Int
block : BlockDef
count_primitive : Primitive
max_count : Int
dimension : FrameLayout
} derive(Debug)pub(all) struct Schema {
id : Int
version : Int
package_name : String
byte_order : ByteOrder
header_layout : FrameLayout
types : Map[String, TypeDef]
messages : Array[MessageDef]
} derive(Debug)Install
Download zipSBE binary message codecs and MoonBit code generation with reference interoperability tests