mirror of
https://github.com/luxfi/vm.git
synced 2026-10-30 15:13:40 +00:00
Wave 2E of codec final rip (#101). The package-local Codec singleton no longer wraps a reflectcodec-backed codec.Manager + linearcodec; it is a hand-rolled two-shape marshaller for the [2]ids.ID sharedID seed and the *dbElement value record stored under each shared-memory key. Public surface is preserved bit-for-bit: - Codec, CodecVersion, Manager interface - Marshal(version, source) ([]byte, error) - Unmarshal(bytes, dest) (uint16, error) Wire format for both supported shapes is byte-identical to the legacy reflectcodec output (verified out-of-band against a side-by-side linearcodec run; new codec_test.go pins fixtures). Existing on-disk shared-memory state and bootstrapped peers therefore remain readable. The codec is now closed by type: any source/dest outside the two registered shapes is rejected with ErrUnsupportedType at marshal / unmarshal time. Adding a new shape is a deliberate change — register a case in marshalValue/unmarshalValue. Max blob size dropped from math.MaxInt to a 64 MiB explicit cap; the two registered shapes are bounded well under that and the cap prevents pathological inputs from allocating up to memory exhaustion at unmarshal time. No consumer changes required: the singleton + interface preserve the exact call surface every internal call site (memory.go::sharedID, state.go::SetValue / RemoveValue / loadValue) already uses.