Skip to content

Json and MsgPack decode through a seed, as Packed does - #31

Merged
Kinflou merged 2 commits into
mainfrom
feat/decode-seed-all-formats
Oct 25, 2026
Merged

Kinflou merged 2 commits into
mainfrom
feat/decode-seed-all-formats

Conversation

@Kinflou

@Kinflou Kinflou commented Oct 25, 2026

Copy link
Copy Markdown
Member
  • Json and MsgPack gain decode_seed, with the signature Packed::decode_seed has, and WireFormat::decode now calls self.decode_seed(PhantomData::<T>, bytes), so the seeded and derived paths are the same code.
  • Why: stage 1 of Shared runtime core: one protocol core every language binds #29. The reference decodes by a type known only at run time, through a DeserializeSeed, and has to equal decoding into a derived type by construction.
  • Behaviour is unchanged. Json spells out serde_json::from_slice (Deserializer::from_slice, then the seed, then end()). MsgPack spells out rmp_serde::from_slice (Deserializer::from_read_ref, default config). That function ignores trailing bytes, and this keeps it that way; a doc comment says so.
  • Tests: seeded equals derived for a struct with an Option, an enum, a Vec and a [u8; 4]; both refuse malformed input; a hand-written seed (an integer width chosen at run time) works for each format.

Kinflou added 2 commits October 25, 2026 14:22
Json and MsgPack gain decode_seed, as Packed has, and decode goes
through it with PhantomData, so the seeded and derived paths are one.
Each spells out its crate's from_slice exactly: serde_json checks the
end of input; rmp_serde does not, and trailing bytes stay ignored.
@Kinflou
Kinflou merged commit 5d98614 into main Oct 25, 2026
6 checks passed
@Kinflou
Kinflou deleted the feat/decode-seed-all-formats branch October 25, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant