-
Notifications
You must be signed in to change notification settings - Fork 13
fix the serializedSize and serialize bug for empty dynamic list #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes a bug in the serializedSize function for slices containing dynamic items. The old implementation incorrectly added a fixed 4-byte overhead for the slice itself when children were dynamic, causing empty slices to report a non-zero size. The new implementation correctly adds 4 bytes for each dynamic child item, ensuring empty slices report zero size and non-empty slices have accurate size calculations.
Key changes:
- Fixed
serializedSizecalculation for slices of dynamic items by moving the 4-byte offset addition inside the loop, per item - Added comprehensive test coverage for empty and non-empty slices of dynamic items
- Added test for structs containing empty dynamic lists to verify correct integration
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/lib.zig | Fixed serializedSize calculation by adding 4-byte offset per dynamic item instead of once for the slice |
| src/tests.zig | Added three comprehensive tests verifying correct size calculation and serialization for empty/non-empty dynamic slices and structs with dynamic fields |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
79dac60 to
cffdb90
Compare
Signed-off-by: Chen Kai <281165273grape@gmail.com>
cffdb90 to
18a774e
Compare
g11tech
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me @gballet have a look
Signed-off-by: Chen Kai <281165273grape@gmail.com>
This pull request improves the serialization logic for arrays and slices of dynamic (variable-sized) items, ensuring that offsets are encoded relative to the start of their containing data rather than as absolute positions. It also adds comprehensive tests to verify correct behavior for empty and non-empty dynamic arrays, slices, and nested structures.
Serialization logic improvements:
serializedSizeto correctly account for offset bytes in arrays and slices of dynamic items, adding 4 bytes per dynamic element as needed.serializeso that offsets for dynamic array and slice elements are written as relative (not absolute) to the start of their containing data, fixing potential deserialization issues with nested structures.Testing enhancements: