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 of String key-value pairs, optimized for compact transport.
  • PairSeqCodec - a reflection-based codec that adapts a domain type to PairSeq by convention.

Conventions

  • Domain types that use PairSeqCodec should provide marshal(): PairSeq and either static unmarshal(PairSeq) or a public constructor T(PairSeq).
  • PairSeq text serialization uses one key=value pair 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
  • Class
    Description
    Codec<T,R>
    General-purpose bidirectional codec between a domain type T and a serialized representation R.
    Immutable sequence of string key-value pairs with cursor-based iteration and simple text serialization.
    Reflection-based Codec that marshals and unmarshals domain objects to and from PairSeq.