LightProto 0.4.0

dotnet add package LightProto --version 0.4.0
                    
NuGet\Install-Package LightProto -Version 0.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LightProto" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LightProto" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="LightProto" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LightProto --version 0.4.0
                    
#r "nuget: LightProto, 0.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LightProto@0.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LightProto&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=LightProto&version=0.4.0
                    
Install as a Cake Tool

LightProto

NuGet License

A high-performance, NativeAOT-compatible Protocol Buffers implementation for C#/.NET, designed as a native aot solution for Protobuf-net.

Why LightProto?

Protobuf-net is a popular choice for Protocol Buffers in .NET,However it has limitations when it comes to NativeAOT scenarios. LightProto addresses these issues by providing a fully NativeAOT-compatible solution with zero runtime overhead.

So, LightProto has three main goals:

  1. NativeAOT Compatibility: Ensure full support for ahead-of-time compilation scenarios without any runtime reflection or code generation.
  2. Protobuf-net Compatibility: Maintain the same serialization behavior and API patterns as Protobuf-net, making migration seamless.
  3. Performance: Performance should be better or at least same as Protobuf-net.

Performance & Benchmarks

The following benchmarks compare serialization performance between LightProto, Protobuf-net, and Google.Protobuf.

You can reproduce these benchmarks by cloning the repository and running the tests/Benchmark project.

BenchmarkDotNet v0.15.2, Windows 11 (10.0.26100.4652/24H2/2024Update/HudsonValley)
AMD Ryzen 7 5800X 3.80GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK 9.0.305
[Host]     : .NET 9.0.9 (9.0.925.41916), X64 RyuJIT AVX2
DefaultJob : .NET 9.0.9 (9.0.925.41916), X64 RyuJIT AVX2
Method Mean Error StdDev Ratio RatioSD Allocated Alloc Ratio
Serialize_ProtoBuf_net 898.8 us 18.29 us 52.48 us 1.61 0.11 526.41 KB 1.03
Serialize_GoogleProtoBuf 651.7 us 16.70 us 48.70 us 1.17 0.10 512.95 KB 1.00
Serialize_LightProto 559.3 us 11.07 us 21.34 us 1.00 0.05 512.95 KB 1.00
Method Mean Error StdDev Ratio RatioSD Allocated Alloc Ratio
Deserialize_ProtoBuf_net 664.9 us 13.28 us 28.00 us 1.53 0.08 562 KB 0.88
Deserialize_GoogleProtoBuf 538.1 us 10.73 us 25.70 us 1.24 0.07 648.7 KB 1.02
Deserialize_LightProto 436.0 us 8.53 us 14.71 us 1.00 0.05 635.15 KB 1.00

⚠️ Development Status

This project is under active development and may introduce breaking changes. use it in production at your own risk.

Todo list:

  • Add more tests for other possible types supported by Protobuf-net
  • Add more benchmarks and performance tests
  • Improve documentation and examples

Quick Start

dotnet add package LightProto

1. Configure your ProtoContracts

using LightProto;
[ProtoContract]
public partial class Person 
{
    [ProtoMember(1)]
    public string Name { get; set; }
    
    [ProtoMember(2)]  
    public int Age { get; set; }
}
var person = new Person { Name = "Alice", Age = 30 };
// Serialization
var bytes = person.ToByteArray();
// or through API in protobuf-net style
var stream = new MemoryStream();
Serializer.Serialize(stream, person);
var bytes = stream.ToArray();

// Deserialization  
var obj = Serializer.Deserialize<Person>(bytes);

Migration from Protobuf-net

Change the namespace from ProtoBuf to LightProto and ensure your classes marked as partial.

-using ProtoBuf;
+using LightProto;
[ProtoContract]
-public class Person
+public partial class Person
{
    [ProtoMember(1)]
    public string Name { get; set; }
    
    [ProtoMember(2)]  
    public int Age { get; set; }
}
var myObject = new MyClass { /* Initialize properties */ };
// Serialization
var stream = new MemoryStream();
Serializer.Serialize(stream, myObject);
byte[] data = stream.ToArray();

// Deserialization  
var obj = Serializer.Deserialize<MyClass>(new MemoryStream(data));

Known Differences

  • Partial Classes: Ensure all protobuf classes are declared as partial to allow the source generator to extend them.
Feature Protobuf-net Behavior LightProto Behavior
Partial Classes No need must
Inheritance Supported Not support
Surrogate Supported Supported(see InstrumentProxy in tests)

If you found any other different behavior with Protobuf-net, please report them via GitHub issues.

.proto files

LightProto does not include a built-in tool for generating C# classes from .proto files. However, you can use the protobuf-net tool to generate the classes and then modify them to be compatible with LightProto.

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

Before contributing:

  1. Check existing issues and discussions
  2. Follow the coding standards used in the project
  3. Add tests for new functionality
  4. Update documentation as needed

Development Setup:

git clone https://github.com/dameng324/LightProto.git
cd LightProto
dotnet restore
dotnet build
dotnet test
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.0 12 9/13/2025