Repository navigation
fix: Ensure SpecificSingleObjectWriter writes header on every call - #438
Merged
Merged
Conversation
Previously, SpecificSingleObjectWriter had a header_written flag that caused it to only write the single-object encoding header on the first call to write_ref(). Subsequent calls would write only the data, making those messages unreadable since they lacked the required header. According to the Avro single-object encoding specification, each message must be independently decodable with its own header (2-byte marker + 8-byte schema fingerprint). This is essential for use cases like message queues where individual messages are stored/transmitted separately. This fix removes the header_written flag and makes write_ref() always write the header, matching GenericSingleObjectWriter's behavior. A new test verifies that multiple writes to the same buffer each produce independently decodable messages.
flxo
force-pushed
the
single-object-header
branch
from
January 26, 2026 09:09
529674d to
5fca352
Compare
Member
|
Could you please extend the example to write more than one objects and respectfully to read them. |
martin-g
reviewed
Jan 26, 2026
use `Write::write_all` instead of `write` to ensure _all_ bytes are written. Co-authored-by: Martin Grigorov <[email protected]>
flxo
force-pushed
the
single-object-header
branch
from
January 26, 2026 10:02
66c24ba to
d7da8c3
Compare
Kriskras99
approved these changes
Jan 26, 2026
Adds a loop that writes the same object twice to ensure the header is correctly written on every call, not just the first one.
Contributor
Author
Extended the example/(test) with a loop. Let me know if you wish changes here. |
martin-g
reviewed
Jan 26, 2026
martin-g
approved these changes
Jan 26, 2026
Member
|
Thank you, @flxo ! |
Contributor
Author
|
Thanks @martin-g and @Kriskras99 for the fast review and merge! |
Closed
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.
Problem
SpecificSingleObjectWriterhad a bug where it only wrote the single-object encoding header on the first call towrite_ref(). Subsequent calls would write only the data without the header, making those messages unreadable.This violated the Avro single-object encoding specification, which requires
that each message be independently decodable with its own header (2-byte marker + 8-byte schema fingerprint). This is critical for use cases like message queues where individual messages are stored or transmitted separately.
Solution
This PR removes the
header_writtenflag fromSpecificSingleObjectWriterand ensures that every call towrite_ref()andwrite()writes a complete single-object encoded message (header + data). This matches the behavior ofGenericSingleObjectWriterand conforms to the Avro specification.Changes
header_writtenfield fromSpecificSingleObjectWriterwrite_ref()to always write the header before writing dataTest Plan
The updated test in
avro/src/writer.rs:1573verifies that:write_ref()produce identical output to callingwrite_value()multiple timesGenericSingleObjectWriterbehaviorFixes #431