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.
I'm working on a server project that relies on this crate to handle NBT fields in the network protocol. To write out packets efficiently, it relies on being able to tell how long each data item will be before serialization begins, but there didn't seem to be a way to do that for NBT values with their existing API. (Beyond extracting sub-values and manually calculating it)
Since other people are likely to need this functionality, I thought I'd submit it as a PR. (I've not made any style changes or warning fixes in other code)
Specifically, the public API addition is that
Value
andBlob
now have aserialized_size
method that reports the number of bytes they will serialize into, without any compression. There is also a new test intests.rs
that constructs a Blob with at least one field of each existing tag, and asserts that the reported serialized size matches the length of the actual serialization output.Hope this is useful to you, let me know if you'd like any changes.