-
Notifications
You must be signed in to change notification settings - Fork 2
Add support for short and ushort types #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Implemented parsing and serialization for short (Int16) and ushort (UInt16) types, including their fixed, zigzag, and packed variants. Updated generator logic, packed repeated support, and added comprehensive tests and proto definitions for these types in both single and array forms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for short (Int16) and ushort (UInt16) types to the LightProto library, enabling serialization and deserialization of these 16-bit integer types. The implementation includes all encoding variants (standard, fixed-size, and zigzag) along with packed repeated field support.
Changes:
- Added parser implementations for Int16 and UInt16 with standard, fixed-size, and zigzag encoding variants
- Updated source generator logic to map Int16/UInt16 types to appropriate parsers based on DataFormat
- Extended PackedRepeated support to include short and ushort types
- Added comprehensive test coverage including both single-value and array scenarios with compatibility tests against Google.Protobuf
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/LightProto/Parser/UInt16.cs | Adds standard varint parser for ushort type |
| src/LightProto/Parser/UInt16.Fixed.cs | Adds fixed32 parser for ushort type |
| src/LightProto/Parser/Int16.cs | Adds standard varint parser for short type |
| src/LightProto/Parser/Int16.Zigzag.cs | Adds zigzag-encoded parser for short type |
| src/LightProto/Parser/Int16.SFixed.cs | Adds fixed32 signed parser for short type |
| src/LightProto/PackedRepeated.cs | Adds short and ushort to supported packed types |
| src/LightProto.Generator/LightProtoGenerator.cs | Updates generator to map Int16/UInt16 types to appropriate parsers and handle fixed size calculations |
| tests/LightProto.Tests/Parsers/parser.proto | Adds proto definitions for short/ushort fields in test messages |
| tests/LightProto.Tests/Parsers/PrimitiveTests.cs | Adds test cases for single short/ushort values |
| tests/LightProto.Tests/Parsers/PrimitiveArrayTests.cs | Adds test cases for short/ushort arrays with packed/unpacked variants |
| tests/LightProto.Tests/NonGenericSerializerTests.cs | Adds non-generic serializer test cases for all short/ushort parser variants |
| } | ||
| } | ||
|
|
||
| sealed class LightProtoWriter : IProtoWriter, IProtoWriter<UInt16> |
Copilot
AI
Jan 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inner class name 'LightProtoWriter' is inconsistent with the naming pattern used in similar parsers. Looking at UInt32ProtoParser, ByteProtoParser, and CharProtoParser, the inner classes are named with type-specific names (e.g., 'UInt32ProtoWriter', 'ByteProtoWriter'). This class should be renamed to 'UInt16ProtoWriter' for consistency.
| [System.Runtime.CompilerServices.MethodImpl( | ||
| System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining | ||
| )] |
Copilot
AI
Jan 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MethodImpl attribute with AggressiveInlining is applied here, but it's not consistently applied in similar simple parsers. ByteProtoParser.ParseFrom does not have this attribute, while Int32ProtoParser does. For consistency and given this is a simple cast operation like ByteProtoParser, consider removing this attribute or ensuring all similar parsers have the same pattern.
| [System.Runtime.CompilerServices.MethodImpl( | |
| System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining | |
| )] |
Exposed Fixed16ProtoParser, Int16ProtoParser, SFixed16ProtoParser, SInt16ProtoParser, and UInt16ProtoParser along with their ProtoReader and ProtoWriter properties in the public API for both net and netstandard2.0 targets.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #166 +/- ##
==========================================
+ Coverage 98.76% 98.79% +0.03%
==========================================
Files 106 111 +5
Lines 2512 2579 +67
Branches 250 250
==========================================
+ Hits 2481 2548 +67
Misses 19 19
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Implemented parsing and serialization for short (Int16) and ushort (UInt16) types, including their fixed, zigzag, and packed variants. Updated generator logic, packed repeated support, and added comprehensive tests and proto definitions for these types in both single and array forms.