Repository navigation
fix(schema): a SchemaField's unread octets are lost through from_data, so a direct SchemaField rebuilds zero-filled - #1397
Merged
Conversation
Owner
Author
|
Cross-review verdict on
Everything else holds:
Nit: |
…, so a direct SchemaField rebuilds zero-filled Schema.unpack now records the octets of a direct SchemaField's span that the nested schema left unread on the nested schema as __remainder__, with the width it read as __remainder_offset__. to_dict() emits both as keys of the nested mapping, from_dict() accepts them back, and Schema.pack re-emits the remainder wherever the nested value goes, as long as the nested schema still packs to that width; a nested schema that shrank or grew is zero-filled as before. from_dict(to_dict()) and Protocol.from_data now rebuild byte-exactly. The keys are absent when nothing was left unread. Closes #1380
JarryShaw
force-pushed
the
fix/1380-schemafield-from-data-remainder
branch
from
October 8, 2026 01:44
cdda580 to
7a1e11b
Compare
Owner
Author
|
Round-2 verdict on
Nit: a non-bytes |
Contributor
|
Coverage: 89.40% (unit tier, Python 3.14,
Per-file detail: the |
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.
Searched for similar pull requests
Followed the coding style (
make pylint,make mypy,make isort) — only pylint E/W and mypy run on the touched files; no new findingsmake testpasses, and a test case covers the change — modules listed belowAdded a changelog entry — N/A, added centrally
fix— corrects a defectCloses #1380
Cause.
Schema.packre-emitted a nested schema's unread octets from__buffer__(schema.py:876-878onmain). A schema rebuilt throughfrom_dictorfrom_datawas never unpacked, so its buffer was empty and the span was zero-filled.Fix.
Schema.unpacknow stores the unread octets on the nested schema as__remainder__, plus the width it read as__remainder_offset__. Both are builtin names, so neither is a field or an item.to_dict()emits both as keys of the nested mapping, andfrom_dict()accepts them.packre-emits the remainder only while the nested schema still packs to that width. A nested schema that shrank or grew is zero-filled, as onmain. Probe:Out2.from_dict(o.to_dict()).pack()was0302000004and is now0302eeee04.Not breaking for shipped protocols: none of the 446 shipped schema classes declares a
SchemaFielddirectly or behind aConditionalField, so theirto_dict()never carries the key. User schemas:to_dict()gainsinner['__remainder__']andinner['__remainder_offset__']. A parsed nested schema that is mutated but keeps its width now keeps the unread octets, where it used to zero-fill them.Tests: the new
tests/protocols/schema/test_schema_field_remainder_unit.pyhas 11 cases. They includeProtocol.from_data, and an in-place and afrom_dictshrink, each of which gives01aa0000000004.test_schema_field_keeps_declared_widthnow expects0302eeee04. Withmain'sschema.py, 5 of the 11 new cases fail, plus the updated case. The two shrink cases fail on the round-1 headcdda5807e. All 32 corekit modules and all 5 schema modules pass, as dotest_protocol_make_unit(12),test_make_raw_item_read_unit(2) andtests/project(391 passed, 1 skipped). Theprotocols --exclude protocols/internetleg ran 993 tests, OK.