Skip to content

refactor: aof serialization helpers and snapshot utf-8 helper#130

Merged
kacy merged 2 commits intomainfrom
refactor/persistence-helpers
Feb 14, 2026
Merged

refactor: aof serialization helpers and snapshot utf-8 helper#130
kacy merged 2 commits intomainfrom
refactor/persistence-helpers

Conversation

@kacy
Copy link
Owner

@kacy kacy commented Feb 14, 2026

summary

aof.rs:

  • added AofRecord::tag() method mapping each variant to its on-disk tag byte
  • hoisted the write_u8(tag) call above the match so all arms share it
  • combined variants with identical serialization shapes using | patterns:
    • key-only: Del | LPop | RPop | Persist | Incr | Decr
    • key + byte list: LPush | RPush
    • key + string list: ZRem | SAdd | SRem
    • key + i64: IncrBy | DecrBy

snapshot.rs:

  • extracted parse_utf8(bytes, field) helper for the String::from_utf8 + map_err pattern that was repeated 6 times in read_plaintext_entry
  • wired the existing read_snap_string (encryption path) to use it too

what was tested

  • cargo test -p ember-persistence --features vector,protobuf — all 76 tests pass
  • cargo clippy -p ember-persistence --features vector,protobuf -- -D warnings — clean

kacy added 2 commits February 14, 2026 17:20
added AofRecord::tag() that maps each variant to its on-disk tag byte.
moved the write_u8(tag) call before the match, then combined variants
with identical serialization shapes:

- key-only: Del | LPop | RPop | Persist | Incr | Decr
- key + byte list: LPush | RPush
- key + string list: ZRem | SAdd | SRem
- key + i64: IncrBy | DecrBy

each group writes the tag once via self.tag(), then shares the payload
serialization logic. unique variants (ZAdd, HSet, VAdd, etc.) keep
their own arms with section comments.
the pattern String::from_utf8(bytes).map_err(|_| FormatError::Io(...))
was repeated 6 times across read_plaintext_entry. extracted a parse_utf8
helper that takes the bytes and a field name for the error message.
also wired the existing read_snap_string (encryption path) to use it.
@kacy kacy merged commit 653414b into main Feb 14, 2026
6 of 7 checks passed
@kacy kacy deleted the refactor/persistence-helpers branch February 14, 2026 22:24
kacy added a commit that referenced this pull request Feb 19, 2026
* refactor: add tag() method, combine aof serialization patterns

added AofRecord::tag() that maps each variant to its on-disk tag byte.
moved the write_u8(tag) call before the match, then combined variants
with identical serialization shapes:

- key-only: Del | LPop | RPop | Persist | Incr | Decr
- key + byte list: LPush | RPush
- key + string list: ZRem | SAdd | SRem
- key + i64: IncrBy | DecrBy

each group writes the tag once via self.tag(), then shares the payload
serialization logic. unique variants (ZAdd, HSet, VAdd, etc.) keep
their own arms with section comments.

* refactor: extract parse_utf8 helper in snapshot deserialization

the pattern String::from_utf8(bytes).map_err(|_| FormatError::Io(...))
was repeated 6 times across read_plaintext_entry. extracted a parse_utf8
helper that takes the bytes and a field name for the error message.
also wired the existing read_snap_string (encryption path) to use it.
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