data NativeEncoder
The writer of the built-in formats handed to a Codec (a handle of the runtime).
Example:
use std.ser { Codec, Encoder, Decoder, Schema, encode, decode, hex, EncodeError, DecodeError }
data Shift {}
impl Codec<i64> for Shift {
static fn encode(x: &i64, w: &var Encoder) -> () | EncodeError { w.writeI64(x + 1) }
static fn decode(r: &var Decoder) -> i64 | DecodeError { r.readI64()? - 1 }
static fn schema() -> Schema => Schema.of("int64")
}
data Subject {
@codec(Shift) n: i64
}
fn main() io {
print(hex(&encode(&Subject{ n: 1 })!))
}Вывод
0802
pub(api) data NativeEncoderС версии. 1.0.0-beta
Определено в: std/ser/ser.oxl:2187