fix: IOWriter write_binary encodes small payloads as fixstr instead of bin8#29
Merged
nuskey8 merged 2 commits intonuskey8:mainfrom Apr 8, 2026
Merged
fix: IOWriter write_binary encodes small payloads as fixstr instead of bin8#29nuskey8 merged 2 commits intonuskey8:mainfrom
IOWriter write_binary encodes small payloads as fixstr instead of bin8#29nuskey8 merged 2 commits intonuskey8:mainfrom
Conversation
… three writer paths (SliceWriter, VecWriter, IOWriter)
There was a problem hiding this comment.
Pull request overview
This PR fixes MessagePack binary encoding in the IOWriter implementation so that small binary payloads are encoded using the proper bin8 format (instead of an incorrect fixstr marker), aligning IOWriter output with the existing SliceWriter and VecWriter behavior. It also adds a cross-path integration test to ensure all Write methods produce identical bytes across writer backends.
Changes:
- Fix
IOWriter::write_binaryto encode0..=255byte payloads withBIN8_MARKER(bin8) rather than an incorrect fixstr marker. - Add
cross_path_test.rsto compare serialized output across VecWriter, SliceWriter, and (when enabled) IOWriter for allWritetrait methods.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
zerompk/src/write.rs |
Corrects IOWriter binary encoding for small payloads to use bin8, matching other writer implementations. |
zerompk/tests/cross_path_test.rs |
Adds cross-writer parity tests that would catch writer-path inconsistencies like the original binary encoding bug. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Owner
|
Merged the PR. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
The
IOWriter'swrite_binarymethod had a0..=31arm that used fixstr format(0xb0 | len)instead of the bin8 marker. This caused small binary payloads (<=31 bytes) to be encoded as strings rather than binary data, making the output inconsistent withSliceWriterandVecWriter.IOWriter
zerompk/zerompk/src/write.rs
Lines 1665 to 1698 in c36e38f
SliceWriter
zerompk/zerompk/src/write.rs
Lines 441 to 486 in c36e38f
VecWriter
zerompk/zerompk/src/write.rs
Lines 1085 to 1124 in c36e38f
Fix
Merged the
0..=31and32..=255arms into a single0..=255arm usingBIN8_MARKER, matchingSliceWriterandVecWriter.Tests
cross_path_test.rs) to verify identical output across all three writer paths (SliceWriter, VecWriter, IOWriter) for everyWritetrait method.cross_path_binary_emptyandcross_path_binary_bin8caught this bug.