Repository navigation
Remove the unused ByteBuf writers from LightProtoCodec - #34
Merged
merlimat merged 2 commits intoOct 2, 2026
Merged
Conversation
Generated code serializes through the raw byte[] and NIO writers, so LightProtoCodec's ByteBuf writers (writeVarInt, writeVarInt64, writeSignedVarInt*, writeFixedInt*, writeFloat, writeDouble and writeString) were only called by tests. The codec is copied into every generated package, along with these 78 unused lines. LightProtoCodecTest and SegmentedByteBufTest now encode with the raw writers that generated code uses. Their assertions are unchanged, so the protobuf-java CodedInputStream checks now cover the production writers, which had no direct unit tests.
Its last readers were the Unsafe raw writers that streamnative#12 replaced with the byte[] writers. The NIO writers added later take the byte order from the buffer itself, with nb.order().
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
LightProtoCodecstill hasByteBufwriters that nothing calls since serialization moved to thebyte[]and NIO writers, and aLITTLE_ENDIANconstant that nothing reads. The codec is a template copied into every generated package, so each copy carries this unused code.Example
writeVarInt,writeVarInt64,writeSignedVarInt,writeSignedVarInt64,writeFixedInt32,writeFixedInt64,writeFloat,writeDouble,writeString, and the private_writeVarIntthey share. Their only callers were tests:LITTLE_ENDIANlost its last readers in #12, which replaced the Unsafe raw writers. The NIO writers added later take the byte order from the buffer itself, withnb.order().Change
Removed the writers and the constant.
LightProtoCodecTestandSegmentedByteBufTestnow encode with the raw writers the generated code uses, into the array the test buffer wraps:The assertions are unchanged: protobuf-java's
CodedInputStreamstill checks the encoding, and the LightProto readers still read it back. So those checks now cover the production writers, which previously had no direct unit tests.Testing
mvn verifypasses: 507 tests, including the 106 inLightProtoCodecTestand 7 inSegmentedByteBufTest.