Package zeroecho.core.marshal
package zeroecho.core.marshal
Marshalling utilities and conventions for compact, human-readable
representations.
This package defines a small SPI for bidirectional codecs and a lightweight text representation for structured metadata. It enables algorithms and specifications to serialize themselves into a simple key-value sequence and reconstruct objects from that form.
Key elements
Codec- a bidirectional contract between a domain type and a serialized representation.PairSeq- an immutable sequence ofStringkey-value pairs, optimized for compact transport.PairSeqCodec- a reflection-based codec that adapts a domain type toPairSeqby convention.
Conventions
- Domain types that use
PairSeqCodecshould providemarshal(): PairSeqand eitherstatic unmarshal(PairSeq)or a public constructorT(PairSeq). PairSeqtext serialization uses onekey=valuepair per line with optional comment lines starting with#. Binary values should be Base64-encoded.
Typical usage
// A small domain type that follows the PairSeq convention.
public record User(String id, String name) {
public PairSeq marshal() {
return PairSeq.of("id", id, "name", name);
}
public static User unmarshal(PairSeq ps) {
String id = null, name = null;
for (PairSeq.Cursor c = ps.cursor(); c.next();) {
if ("id".equals(c.key())) id = c.value();
else if ("name".equals(c.key())) name = c.value();
}
return new User(id, name);
}
}
// Use a reflection-based codec for the domain type.
PairSeqCodec<User> codec = new PairSeqCodec<>(User.class);
PairSeq repr = codec.marshal(new User("u-1", "Alice"));
User copy = codec.unmarshal(repr);
- Since:
- 1.0
-
ClassDescriptionCodec<T,
R> General-purpose bidirectional codec between a domain typeTand a serialized representationR.Immutable sequence of string key-value pairs with cursor-based iteration and simple text serialization.PairSeqCodec<T>