Bounded XDR schema interpreter, binary interchange and ONC RPC wire toolkit in pure MoonBit
moon add kekeshuo/moonxdr@0.1.0let schema = @xdr.parse_schema("struct Item { unsigned int id; string title<32>; };")
let item = @xdr.VStruct([("id", @xdr.VUInt(7U)), ("title", @xdr.VString("hello"))])
let wire = @xdr.encode(schema, "Item", item)
let restored = @xdr.decode(schema, "Item", wire)
assert_true(@xdr.encode(schema, "Item", restored) == wire)moon run examples/schema --deny-warn
moon run examples/rpc --deny-warn
moon run examples/interchange --deny-warn| XDR | JSON |
|---|---|
| int / uint | checked integral number (integer lexical form when parsed) |
| hyper / unsigned hyper | exact decimal string |
| enum | input name or signed32 number; numeric output |
| opaque | even-length hexadecimal string, no whitespace |
| optional | null or {"some": VALUE}; wrapper preserves nested optionals |
| struct / array | exact-key object / array |
| union | {"tag": NUMBER, "value": VALUE} |
| void | null |
moon info && moon fmt
moon fmt --check
moon check --deny-warn
moon build --deny-warn
moon test --deny-warn
python scripts/reference_vectors.py --check
python scripts/audit.pypub(all) enum AcceptStatus {
Success(Array[Byte])
ProgramUnavailable
ProgramMismatch(UInt, UInt)
ProcedureUnavailable
GarbageArguments
SystemError
}pub(all) struct Limits {
max_bytes : Int
max_items : Int
max_depth : Int
max_schema_tokens : Int
}fn RecordDecoder::feed(self : RecordDecoder, chunk : Array[Byte]) -> Array[Array[Byte]] raise XdrErrorpub(all) struct RpcCall {
xid : UInt
program : UInt
version : UInt
procedure : UInt
credential : OpaqueAuth
verifier : OpaqueAuth
arguments : Array[Byte]
}Install
Download zipBounded XDR schema interpreter, binary interchange and ONC RPC wire toolkit in pure MoonBit