Amazon Ion 1.0 text and binary codec for MoonBit
Ion text ──► 词法 / 容器解析 ──► IonValue
Ion binary ─► BVM + type descriptor ─► IonValue
│
▼
dumps / dumps_bytes
│
Ion text 或 Ion binaryimport {
"ZJH-666-ZJH/moonion" @ion,
}///|
fn main {
match @ion.load("Product::{ id: \"sku-42\", count: 3 }") {
Ok(v) => {
println(@ion.dumps(v))
let binary = @ion.dumps_bytes(v)
match @ion.load_bytes(binary) {
Ok(again) => println(again.annotations[0])
Err(e) => println(e.message())
}
}
Err(e) => println(e.message())
}
}///|
fn main {
let product = @ion.catalog_sample()
println(@ion.dumps_all([product, @ion.sexp_sample()]))
}moon add ZJH-666-ZJH/moonion@0.1.1moon run examples/catalog_record
moon run examples/binary_roundtrip
moon run examples/sexp_filter
moon run cmd/mainpub(all) enum IonError {
UnexpectedEof
InvalidBinary(String)
InvalidText(String)
InvalidUtf8
InvalidSymbol(String)
InvalidTimestamp(String)
InvalidDecimal(String)
InvalidNumber(String)
InvalidBlob(String)
InvalidAnnotation(String)
InvalidSymbolTable(String)
Unsupported(String)
EmptyDocument
} derive(Eq, Debug)pub(all) struct IonTimestamp {
year : Int
month : Int
day : Int
hour : Int
minute : Int
second : Int
fraction : IonDecimal
offset_minutes : Int
offset_unknown : Bool
precision : TimestampPrecision
} derive(Eq, Debug)fn f64_from_be_bytes(b0 : Int, b1 : Int, b2 : Int, b3 : Int, b4 : Int, b5 : Int, b6 : Int, b7 : Int) -> Doublefn timestamp_of(year : Int, month : Int, day : Int, hour : Int, minute : Int, second : Int, fraction : IonDecimal, offset_minutes : Int, offset_unknown : Bool, precision : TimestampPrecision) -> Result[IonTimestamp, IonError]Install
Download zipAmazon Ion 1.0 text and binary codec for MoonBit