protobuf-net /protobuf-net

Protocol Buffers library for idiomatic .NET

★ 4,974⑂ 1,090👁 211⑃ 497● 886▤ 18
C#NOASSERTIONCreated 2014-06-16docs.protobuf-net.dev/
下载:3.4.403.4.40 ↓3.4.402026-10-21
-1
日增长
4,974
stars
1,090
forks
211
watchers
497
prs
886
issues
18
releases

README

protobuf-net

!protobuf-net logo protobuf-net is a contract based serializer for .NET code, that happens to write data in the "protocol buffers" serialization format engineered by Google. The API, however, is very different to Google's, and follows typical .NET patterns (it is broadly comparable, in usage, to XmlSerializer, DataContractSerializer, etc). It should work for most .NET languages that write standard types and can use attributes.



Recent changes are on the releases page; older
history is in the release notes.

 New: protobuf-net.Connect — the
 Connect protocol for .NET. gRPC semantics over ordinary HTTP, so unary and
 one-way streaming work over HTTP/1.1, through proxies and CDNs that will not carry gRPC. Reuses
 protobuf-net.Grpc contracts unchanged; AOT-first; full conformance both directions.

 Online tools: protobuf-net.dev

Free, browser-based, and nothing to install — and it all runs locally: it is a static site, so your
schemas and payloads never leave your machine. You can:

- generate C/VB types from a .proto schema — the same code generation as the
  protogen global tool
- decode a raw protobuf payload, without needing the schema that produced it

Documentation is at docs.protobuf-net.dev.

 Supported Runtimes
- .NET 6.0+ (.NET 5 etc will use .NET Standard 2.1)
- .NET Standard 2.0, 2.1
- .NET Framework 4.6.2+

 Native AOT and trimming

From 3.3, protobuf-net can generate serializers at build time from code-first contracts, making native AOT and trimming work — and improving cold start even on ordinary JIT builds. See the AOT documentation.

The build tools (analyzers that validate contracts, and this generator) are included in the protobuf-net package by default; opt out with true.

 Runtime Installation

All stable and some pre-release packages are available on NuGet.

You can use the following command in the Package Manager Console:
ps
Install-Package protobuf-net


| Package | NuGet Stable | NuGet Pre-release | Downloads |
| ------- | ------------ | ----------------- | --------- |
| protobuf-net |  |  |  |

 Basic usage

 1 First Decorate your classes
csharp
[ProtoContract]
class Person {
    [ProtoMember(1)]
    public int Id {get;set;}
    [ProtoMember(2)]
    public string Name {get;set;}
    [ProtoMember(3)]
    public Address Address {get;set;}
}
[ProtoContract]
class Address {
    [ProtoMember(1)]
    public string Line1 {get;set;}
    [ProtoMember(2)]
    public string Line2 {get;set;}
}

Note that unlike XmlSerializer, the member-names are not encoded in the data - instead, you must pick an integer to identify each member. Additionally, to show intent it is necessary to show that we intend this type to be serialized (i.e. that it is a data contract).

 2 Serialize your data

This writes a 32 byte file to "person.bin" :
csharp
var person = new Person {
    Id = 12345, Name = "Fred",
    Address = new Address {
        Line1 = "Flat 1",
        Line2 = "The Meadows"
    }
};
using (var file = File.Create("person.bi

Top issues

Latest release

3.4.40 3.4.40 2026-10-21
What's Changed
 Contract-first codegen: opt-out of unknown-field preservation (PreserveUnknownFields) by @mgravell in https://github.com/protobuf-net/protobuf-net/pull/1368
 Fix StreamProtoReader pool state corruption after interrupted fixed-length deserialization by @PauloHMattos in https://github.com/protobuf-net/protobuf-net/pull/1376

 Maintenance
 Drop the explicit Microsoft.SourceLink.GitHub reference by @mgravell in https://github.com/protobuf-net/protobuf-net/pull/1355
 Bump Grpc.Net.Client from 2.83.0 to 2.84.0 by @dependabot[bot] in https://github.com/protobuf-net/protobuf-net/

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON