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

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

Using byte in a ProtoContract resulted in compilation errors due to missing ByteProtoParser. This adds full support for the byte primitive type.

Changes

Runtime support (src/LightProto/Parser/Byte.cs, ReaderContext.cs, WriterContext.cs, CodedOutputStream.ComputeSize.cs)

  • Added ByteProtoParser following existing primitive parser patterns
  • Added ReadByte(), WriteByte(), and ComputeByteSize() methods
  • Uses varint encoding (1 byte for 0-127, 2 bytes for 128-255)

Generator mappings (src/LightProto.Generator/LightProtoGenerator.cs)

  • Mapped SpecialType.System_Byte to "Byte" parser
  • Added byte to wire type and fixed size tables

Public API (PublicAPI.Unshipped.txt files)

  • Registered new public APIs for both net and netstandard2.0 targets

Tests (tests/LightProto.Tests/Parsers/ByteTests.cs)

  • Added serialization validation and round-trip tests for all 256 byte values

Usage

[ProtoContract]
public partial class MyMessage
{
    [ProtoMember(1)]
    public byte Data { get; set; }  // Now supported
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Regarding the byte type</issue_title>
<issue_description>```csharp
[ProtoContract]
public partial class AssemblyParserPersonContract
{
[ProtoMember(1)]
public Person? Person { get; set; }
[ProtoMember(2)]
public byte Data { get; set; }
}


The above definition will result in LightProto.Parser.ByteProtoParser.ProtoWriter appearing in the generated code; the editor will prompt that ByteProtoParser is missing.</issue_description>

<agent_instructions>Add byte type support, use varint wire format.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@dameng324</author><body>
Thanks for your feedback. 

It will be fixed in future release.</body></comment_new>
</comments>

Custom agent used: C# Expert
An agent designed to assist with software development tasks for .NET projects.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Jan 14, 2026
Copilot AI changed the title [WIP] Add byte type support using varint wire format Add byte type support with varint wire format Jan 14, 2026
Copilot AI requested a review from dameng324 January 14, 2026 07:30
@dameng324 dameng324 changed the title Add byte type support with varint wire format Add byte/sbyte type support Jan 14, 2026
Registered ByteProtoParser and SByteProtoParser in the serializer. Extended tests to cover byte, sbyte, and List<sbyte> serialization. Removed redundant ByteListTests as coverage is now included in NonGenericSerializerTests.
@dameng324 dameng324 marked this pull request as ready for review January 14, 2026 13:12
Copilot AI review requested due to automatic review settings January 14, 2026 13:12
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.75%. Comparing base (8df571f) to head (3d6bf28).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #160      +/-   ##
==========================================
+ Coverage   98.72%   98.75%   +0.02%     
==========================================
  Files         101      105       +4     
  Lines        2440     2497      +57     
  Branches      250      250              
==========================================
+ Hits         2409     2466      +57     
  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 RatioSD Allocated Alloc Ratio
Deserialize_ProtoBuf_net .NET 10.0 .NET 10.0 792.1 μs 4.00 μs 3.74 μs 1.33 0.01 562 KB 0.98
Deserialize_GoogleProtoBuf .NET 10.0 .NET 10.0 619.9 μs 2.81 μs 2.35 μs 1.04 0.01 648.7 KB 1.13
Deserialize_LightProto .NET 10.0 .NET 10.0 595.5 μs 3.78 μs 3.35 μs 1.00 0.01 574.8 KB 1.00
Deserialize_ProtoBuf_net .NET 8.0 .NET 8.0 951.8 μs 4.09 μs 3.41 μs 1.57 0.02 562 KB 0.98
Deserialize_GoogleProtoBuf .NET 8.0 .NET 8.0 827.9 μs 2.23 μs 1.74 μs 1.37 0.01 648.7 KB 1.13
Deserialize_LightProto .NET 8.0 .NET 8.0 605.9 μs 6.64 μs 6.21 μs 1.00 0.01 574.8 KB 1.00
Deserialize_ProtoBuf_net .NET 9.0 .NET 9.0 830.2 μs 8.19 μs 6.84 μs 1.41 0.02 562 KB 0.98
Deserialize_GoogleProtoBuf .NET 9.0 .NET 9.0 709.3 μs 6.99 μs 6.19 μs 1.21 0.02 648.7 KB 1.13
Deserialize_LightProto .NET 9.0 .NET 9.0 588.3 μs 6.59 μs 6.17 μs 1.00 0.01 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 901.1 μs 1.61 μs 1.42 μs 1.31 526.41 KB 1.03
Serialize_GoogleProtoBuf .NET 10.0 .NET 10.0 782.8 μs 2.09 μs 1.75 μs 1.14 512.95 KB 1.00
Serialize_LightProto .NET 10.0 .NET 10.0 689.3 μs 1.00 μs 0.94 μs 1.00 512.92 KB 1.00
Serialize_ProtoBuf_net .NET 8.0 .NET 8.0 1,019.1 μs 2.85 μs 2.66 μs 1.35 526.4 KB 1.03
Serialize_GoogleProtoBuf .NET 8.0 .NET 8.0 855.7 μs 2.53 μs 1.98 μs 1.14 512.95 KB 1.00
Serialize_LightProto .NET 8.0 .NET 8.0 752.4 μs 1.48 μs 1.38 μs 1.00 512.92 KB 1.00
Serialize_ProtoBuf_net .NET 9.0 .NET 9.0 986.2 μs 3.25 μs 2.72 μs 1.31 526.4 KB 1.03
Serialize_GoogleProtoBuf .NET 9.0 .NET 9.0 813.1 μs 1.56 μs 1.30 μs 1.08 512.95 KB 1.00
Serialize_LightProto .NET 9.0 .NET 9.0 750.6 μs 1.38 μs 1.29 μs 1.00 512.92 KB 1.00

@dameng324 dameng324 merged commit f6f64b1 into main Jan 14, 2026
8 checks passed
@dameng324 dameng324 deleted the copilot/add-byte-type-support branch January 14, 2026 13:54
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.

Regarding the byte type

2 participants