Skip to content

Remove the unused ByteBuf writers from LightProtoCodec - #34

Merged
merlimat merged 2 commits into
streamnative:masterfrom
merlimat:remove-unused-bytebuf-writers
Oct 2, 2026
Merged

merlimat merged 2 commits into
streamnative:masterfrom
merlimat:remove-unused-bytebuf-writers

Conversation

@merlimat

@merlimat merlimat commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

LightProtoCodec still has ByteBuf writers that nothing calls since serialization moved to the byte[] and NIO writers, and a LITTLE_ENDIAN constant 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 _writeVarInt they share. Their only callers were tests:

LightProtoCodec.writeVarInt(bb, i);   // LightProtoCodecTest: encode, then check with CodedInputStream and readVarInt()

LITTLE_ENDIAN lost its last readers in #12, which replaced the Unsafe raw writers. The NIO writers added later take the byte order from the buffer itself, with nb.order().

Change

Removed the writers and the constant. LightProtoCodecTest and SegmentedByteBufTest now encode with the raw writers the generated code uses, into the array the test buffer wraps:

bb.writerIndex(LightProtoCodec.writeRawVarInt(b, 0, i));

The assertions are unchanged: protobuf-java's CodedInputStream still 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 verify passes: 507 tests, including the 106 in LightProtoCodecTest and 7 in SegmentedByteBufTest.

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().
@merlimat
merlimat merged commit 61d497f into streamnative:master Oct 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant