collections: write wincode vec elements via schema to match reader#197
Merged
febo merged 2 commits intoJul 7, 2026
Merged
Conversation
Contributor
|
@febo can you take a look? |
Contributor
|
Thanks for the PR @plutohan! I left a comment on the issue since supporting non-pod types might affect how JS handles these types. Let's wait to see what @lorisleiva says about it. |
febo
requested changes
Jul 6, 2026
febo
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me. Just left a few nits.
Comment on lines
+145
to
+150
| // Sum the serialized size of each element, matching the per-element | ||
| // decoding performed by the read side. | ||
| let mut expected_size = 0usize; | ||
| for item in src.0.iter() { | ||
| expected_size = expected_size.saturating_add(<T as SchemaWrite<C>>::size_of(item)?); | ||
| } |
Contributor
There was a problem hiding this comment.
nit: We could use try_fold here.
Suggested change
| // Sum the serialized size of each element, matching the per-element | |
| // decoding performed by the read side. | |
| let mut expected_size = 0usize; | |
| for item in src.0.iter() { | |
| expected_size = expected_size.saturating_add(<T as SchemaWrite<C>>::size_of(item)?); | |
| } | |
| // Sum the serialized size of each element, matching the per-element | |
| // decoding performed by the read side. | |
| let expected_size = src | |
| .0 | |
| .iter() | |
| .try_fold(0usize, |size, item| -> WriteResult<usize> { | |
| Ok(size.saturating_add(<T as SchemaWrite<C>>::size_of(item)?)) | |
| })?; |
Comment on lines
166
to
171
| for item in src.0.iter() { | ||
| <T as SchemaWrite<C>>::write(&mut writer, item)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
Contributor
There was a problem hiding this comment.
nit: Same here, we can use try_for_each.
Suggested change
| for item in src.0.iter() { | |
| <T as SchemaWrite<C>>::write(&mut writer, item)?; | |
| } | |
| Ok(()) | |
| } | |
| src.0 | |
| .iter() | |
| .try_for_each(|item| T::write(&mut writer, item)) | |
| } |
Comment on lines
+277
to
+281
| let mut expected_size = core::mem::size_of::<$prefix_type>(); | ||
| for item in src.0.iter() { | ||
| expected_size = expected_size | ||
| .saturating_add(<T as SchemaWrite<C>>::size_of(item)?); | ||
| } |
Contributor
There was a problem hiding this comment.
nit: Same as above, try_fold.
Suggested change
| let mut expected_size = core::mem::size_of::<$prefix_type>(); | |
| for item in src.0.iter() { | |
| expected_size = expected_size | |
| .saturating_add(<T as SchemaWrite<C>>::size_of(item)?); | |
| } | |
| let expected_size = src | |
| .0 | |
| .iter() | |
| .try_fold(core::mem::size_of::<$prefix_type>(), |size, item| -> WriteResult<usize> { | |
| Ok(size.saturating_add(<T as SchemaWrite<C>>::size_of(item)?)) | |
| })?; |
Comment on lines
+302
to
+306
| for item in src.0.iter() { | ||
| <T as SchemaWrite<C>>::write(&mut writer, item)?; | ||
| } | ||
|
|
||
| Ok(()) |
Contributor
There was a problem hiding this comment.
nit: Same as above, try_for_each.
Suggested change
| for item in src.0.iter() { | |
| <T as SchemaWrite<C>>::write(&mut writer, item)?; | |
| } | |
| Ok(()) | |
| src.0 | |
| .iter() | |
| .try_for_each(|item| T::write(&mut writer, item)) |
Contributor
Author
|
Applied, 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.
Fixes #196.
The wincode
SchemaWriteimpls forTrailingVecand the prefixed-vec wrappers wrote elements as a raw byte copy sized bysize_of::<T>(), while the read side decodes each element via its schema. For non-PODTthose sizes disagree and the parse boundary drifts, so the field after the vector decodes wrong.Both impls now write and size each element through
SchemaWrite, matching the reader. No wire-format change for POD types. Added non-POD round-trip regression tests with a trailing field to pin the parse boundary.