encoding
extra serialization formats
Additions to
encoding, reusing the same reflection machinery (§10) that already gives native-binary + JSON. SinceSerializableis auto-derived byreflect(T), a new format is just a pair of molds (to_<fmt>/from_<fmt>) sweeping the same kinds, which comes cheap. Tier 1.
MessagePack and CBOR: schema-less binaries
Section titled “MessagePack and CBOR: schema-less binaries”They reuse reflect directly (they are, like native-binary, “structs become bytes”; only the wire format changes):
fn msgpack.encode[T](v: T) -> []bytefn msgpack.decode[T](data: []byte) -> Result[T, error{Malformed, Truncated}]fn cbor.encode[T](v: T) -> []bytefn cbor.decode[T](data: []byte) -> Result[T, error{Malformed, Truncated}]They also expose the dynamic tree (like json.Value) for data without a static type: msgpack.Value/
cbor.Value, with the same accessors (get/as_int/…) as json.Value.
TOML: config
Section titled “TOML: config”Fits with mk.project already being a manifest. Typed (derives onto a struct) and dynamic:
fn toml.decode[T](text: string) -> Result[T, error{Malformed}]fn toml.encode[T](v: T) -> stringfn toml.parse(text: string) -> Result[Value, error{Malformed}] // dynamic treeCSV: tabular
Section titled “CSV: tabular”Streaming (line by line over Readable/Writeable, io.scanner style), with optional header:
fn csv.reader(r: Readable) -> CsvReaderfn (c: *CsvReader) rows() -> Iterator[List[string]] // each line already splitfn (c: *CsvReader) records[T]() -> Iterator[Result[T, error{Malformed}]] // maps to struct (header to field)fn (c: CsvReader) err() -> Optional[error] // error outside the loop (like Scanner)
fn csv.writer(w: Writeable) -> CsvWriterfn (c: *CsvWriter) write_row(fields: []string) -> error{Io}fn (c: *CsvWriter) write_record[T](v: T) -> error{Io} // struct to linedecl CsvOptions { pub delimiter: byte; pub has_header: bool; pub quote: byte }Curation
Section titled “Curation”- They reuse reflect, not a new system: msgpack/cbor are the same “kind to bytes” as native-binary with another wire; toml/csv map struct to text by the same descriptors. Marginal cost.
- Out: YAML (ambiguous and treacherous grammar, high cost and low return in our use); Protobuf (requires
schema/IDL, does not fit here: see note in the queue; the
protocplugin is tooling, and native binary RPC is the futurerpclib over the typedChannel[T]). - Each format is opt-in (
use encoding.msgpacketc.): whoever does not use it does not pay.