Skip to content

refactor: use one snapshot entry codec - #414

Merged
kacy merged 1 commit into
mainfrom
refactor/one-snapshot-codec
Sep 24, 2026
Merged

kacy merged 1 commit into
mainfrom
refactor/one-snapshot-codec

Conversation

@kacy

@kacy kacy commented Sep 24, 2026

Copy link
Copy Markdown
Owner

snapshot.rs had the value encoding written out three times: SnapshotWriter::write_entry, serialize_entry for replication snapshots, and serialize_snap_value for DUMP and MIGRATE. It had the decoding four times: parse_snap_value, read_plaintext_entry, read_entry_with_bytes, and the encrypted reader's inline copy. The two plaintext readers also re-encoded every field into a buffer as they read it, only to feed the footer CRC.

Now:

  • write_snap_value writes [type_tag][payload]. encode_entry adds the key and expiry around it, and all three writers use it.
  • decode_entry reads an entry, including version-1 entries without a type tag. The file reader, the encrypted reader and read_snapshot_from_bytes all use it.
  • The readers feed the footer CRC by wrapping the stream in the existing format::CrcReader and combining its hasher into the running one (crc32fast::Hasher::combine). CrcReader gains into_hasher for this.

The file format and the public functions are unchanged. snapshot.rs loses about 400 lines. The existing round-trip tests cover every value type, with and without the encryption, protobuf and vector features.

Snapshot values were encoded in three places and decoded in four. The
plaintext file reader re-encoded every field it read to feed the footer
CRC, and the replication path had its own reader doing the same. Now
write_snap_value and encode_entry write every entry, decode_entry reads
it, and readers feed the CRC through CrcReader.
@kacy
kacy merged commit 3235ca9 into main Sep 24, 2026
12 checks passed
@kacy
kacy deleted the refactor/one-snapshot-codec branch September 24, 2026 21:06
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