Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dameng324
Copy link
Owner

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.

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.
Copilot AI review requested due to automatic review settings January 15, 2026 08:30
Copy link
Contributor

Copilot AI left a 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>
Copy link

Copilot AI Jan 15, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +17
[System.Runtime.CompilerServices.MethodImpl(
System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining
)]
Copy link

Copilot AI Jan 15, 2026

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.

Suggested change
[System.Runtime.CompilerServices.MethodImpl(
System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining
)]

Copilot uses AI. Check for mistakes.
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
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.79%. Comparing base (4d7edf1) to head (e8dc30b).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link


BenchmarkDotNet v0.15.3, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.101
  [Host]    : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 10.0 : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v3
  .NET 8.0  : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 9.0  : .NET 9.0.12 (9.0.12, 9.0.1225.60609), X64 RyuJIT x86-64-v3


Method Job Runtime Mean Error StdDev Ratio Allocated Alloc Ratio
Deserialize_ProtoBuf_net .NET 10.0 .NET 10.0 753.8 μs 1.68 μs 1.40 μs 1.27 562 KB 0.98
Deserialize_GoogleProtoBuf .NET 10.0 .NET 10.0 603.6 μs 1.81 μs 1.51 μs 1.02 648.7 KB 1.13
Deserialize_LightProto .NET 10.0 .NET 10.0 591.9 μs 2.16 μs 1.81 μs 1.00 574.8 KB 1.00
Deserialize_ProtoBuf_net .NET 8.0 .NET 8.0 882.7 μs 1.24 μs 1.16 μs 1.53 562 KB 0.98
Deserialize_GoogleProtoBuf .NET 8.0 .NET 8.0 791.6 μs 0.75 μs 0.67 μs 1.37 648.7 KB 1.13
Deserialize_LightProto .NET 8.0 .NET 8.0 577.4 μs 1.74 μs 1.36 μs 1.00 574.8 KB 1.00
Deserialize_ProtoBuf_net .NET 9.0 .NET 9.0 824.2 μs 3.60 μs 3.19 μs 1.46 562 KB 0.98
Deserialize_GoogleProtoBuf .NET 9.0 .NET 9.0 691.4 μs 2.61 μs 2.44 μs 1.23 648.7 KB 1.13
Deserialize_LightProto .NET 9.0 .NET 9.0 563.0 μs 0.93 μs 0.73 μs 1.00 574.8 KB 1.00

BenchmarkDotNet v0.15.3, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.101
  [Host]    : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 10.0 : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v3
  .NET 8.0  : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 9.0  : .NET 9.0.12 (9.0.12, 9.0.1225.60609), X64 RyuJIT x86-64-v3


Method Job Runtime Mean Error StdDev Ratio Allocated Alloc Ratio
Serialize_ProtoBuf_net .NET 10.0 .NET 10.0 899.9 μs 4.16 μs 3.68 μs 1.31 526.41 KB 1.03
Serialize_GoogleProtoBuf .NET 10.0 .NET 10.0 792.4 μs 1.55 μs 1.45 μs 1.15 512.95 KB 1.00
Serialize_LightProto .NET 10.0 .NET 10.0 688.5 μs 1.62 μs 1.35 μs 1.00 512.92 KB 1.00
Serialize_ProtoBuf_net .NET 8.0 .NET 8.0 1,034.4 μs 3.61 μs 3.01 μs 1.36 526.4 KB 1.03
Serialize_GoogleProtoBuf .NET 8.0 .NET 8.0 806.2 μs 2.15 μs 2.01 μs 1.06 512.95 KB 1.00
Serialize_LightProto .NET 8.0 .NET 8.0 758.1 μs 8.71 μs 7.28 μs 1.00 512.92 KB 1.00
Serialize_ProtoBuf_net .NET 9.0 .NET 9.0 985.8 μs 1.96 μs 1.64 μs 1.29 526.4 KB 1.03
Serialize_GoogleProtoBuf .NET 9.0 .NET 9.0 790.0 μs 1.58 μs 1.40 μs 1.04 512.95 KB 1.00
Serialize_LightProto .NET 9.0 .NET 9.0 762.7 μs 1.24 μs 1.04 μs 1.00 512.92 KB 1.00

@dameng324 dameng324 merged commit edfd782 into main Jan 15, 2026
8 checks passed
@dameng324 dameng324 deleted the add-short-ushort-support branch January 15, 2026 08:56
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.

2 participants