protobuf-net.Core 3.2.45

Prefix Reserved
dotnet add package protobuf-net.Core --version 3.2.45                
NuGet\Install-Package protobuf-net.Core -Version 3.2.45                
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="protobuf-net.Core" Version="3.2.45" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add protobuf-net.Core --version 3.2.45                
#r "nuget: protobuf-net.Core, 3.2.45"                
#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.
// Install protobuf-net.Core as a Cake Addin
#addin nuget:?package=protobuf-net.Core&version=3.2.45

// Install protobuf-net.Core as a Cake Tool
#tool nuget:?package=protobuf-net.Core&version=3.2.45                

<img src="https://protogen.marcgravell.com/images/protobuf-net.svg" alt="protobuf-net logo" width="45" height="45"> protobuf-net

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.

Build status

Release Notes

v3 is here!

Change history and pending changes are here.


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+

Build tools

Build tools to help you use protobuf-net correctly are available via protobuf-net.BuildTools

Runtime Installation

All stable and some pre-release packages are available on NuGet. CI Builds are available via MyGet (feed URL: https://www.myget.org/F/protobuf-net/api/v3/index.json ).

You can use the following command in the Package Manager Console:

Install-Package protobuf-net
Package NuGet Stable NuGet Pre-release Downloads MyGet
protobuf-net protobuf-net protobuf-net protobuf-net protobuf-net MyGet

Basic usage

1 First Decorate your classes

[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" :

var person = new Person {
    Id = 12345, Name = "Fred",
    Address = new Address {
        Line1 = "Flat 1",
        Line2 = "The Meadows"
    }
};
using (var file = File.Create("person.bin")) {
    Serializer.Serialize(file, person);
}

3 Deserialize your data

This reads the data back from "person.bin" :

Person newPerson;
using (var file = File.OpenRead("person.bin")) {
    newPerson = Serializer.Deserialize<Person>(file);
}

Notes

Notes for Identifiers
  • they must be positive integers (for best portability, they should be <= 536870911 and not in the range 19000-19999)
  • they must be unique within a single type but the same numbers can be re-used in sub-types if inheritance is enabled
  • the identifiers must not conflict with any inheritance identifiers (discussed later)
  • lower numbers take less space - don't start at 100,000,000
  • the identifier is important; you can change the member-name, or shift it between a property and a field, but changing the identifier changes the data

Advanced subjects

Inheritance

Inheritance must be explicitly declared, in a similar way that it must for XmlSerializer and DataContractSerializer. This is done via [ProtoInclude(...)] on each type with known sub-types:

[ProtoContract]
[ProtoInclude(7, typeof(SomeDerivedType))]
class SomeBaseType {...}

[ProtoContract]
class SomeDerivedType {...}

There is no special significance in the 7 above; it is an integer key, just like every [ProtoMember(...)]. It must be unique in terms of SomeBaseType (no other [ProtoInclude(...)] or [ProtoMember(...)] in SomeBaseType can use 7), but does not need to be unique globally.

.proto file

As an alternative to writing your classes and decorating them, You can generate your types from a .proto schema using protogen; the protogen tool is available as a zip from that location, or as a "global tool" (multi-platform).

Alternative to attributes

In v2+, everything that can be done with attributes can also be configured at runtime via RuntimeTypeModel. The Serializer.* methods are basically just shortcuts to RuntimeTypeModel.Default., so to manipulate the behaviour of Serializer., you must configure RuntimeTypeModel.Default.

Support

I try to be responsive to Stack Overflow questions in the protobuf-net tag, issues logged on GitHub, email, etc. I don't currently offer a paid support channel. If I've helped you, feel free to buy me a coffee or see the "Sponsor" link at the top of the GitHub page.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (51)

Showing the top 5 NuGet packages that depend on protobuf-net.Core:

Package Downloads
protobuf-net

Provides simple access to fast and efficient "Protocol Buffers" serialization from .NET applications

protobuf-net.Reflection

ProtoBuf DSL (proto2 / proto3) and descriptor tools for protobuf-net

protobuf-net.Grpc.Reflection

Package Description

Neuroglia.Serialization.Dynamic

Package Description

protobuf-net.MSBuild

Package Description

GitHub repositories (13)

Showing the top 5 popular GitHub repositories that depend on protobuf-net.Core:

Repository Stars
HaoDong108/DouyinBarrageGrab
基于系统代理的抖音弹幕wss抓取程序,能够获取所有数据来源,包括chrome,抖音直播伴侣等,可进行进程过滤
protobuf-net/protobuf-net.Grpc
GRPC bindings for protobuf-net and grpc-dotnet
yswenli/SAEA
SAEA.Socket is a high-performance IOCP framework TCP based on dotnet standard 2.0; Src contains its application test scenarios, such as websocket,rpc, redis driver, MVC WebAPI, lightweight message server, ultra large file transmission, etc. SAEA.Socket是一个高性能IOCP框架的 TCP,基于dotnet standard 2.0;Src中含有其应用测试场景,例如websocket、rpc、redis驱动、MVC WebAPI、轻量级消息服务器、超大文件传输等
rasta-mouse/SharpC2
Command and Control Framework written in C#
geel9/SteamAuth
A C# library that provides vital Steam Mobile Authenticator functionality
Version Downloads Last updated
3.2.45 245,696 10/23/2024
3.2.30 8,409,098 9/27/2023
3.2.26 3,582,752 5/25/2023
3.2.16 1,972,777 3/17/2023
3.2.12 4,169,872 3/4/2023
3.2.8 82,074 2/27/2023
3.2.0 149,456 2/20/2023
3.1.33 2,627,700 1/30/2023
3.1.26 1,565,657 12/16/2022
3.1.25 1,596,734 11/9/2022
3.1.22 1,327,113 9/21/2022
3.1.17 3,041,373 6/26/2022
3.1.4 2,131,919 5/10/2022
3.1.0 640,147 4/22/2022
3.0.131 55,430 4/22/2022
3.0.101 11,968,450 3/19/2021
3.0.73 3,796,022 12/2/2020
3.0.72 7,549 12/2/2020
3.0.62 280,842 11/13/2020
3.0.52 1,461,482 10/3/2020
3.0.29 2,687,809 7/8/2020
3.0.27 79,406 7/6/2020
3.0.24 17,048 7/6/2020
3.0.21 12,328 7/5/2020
3.0.18 5,792 7/5/2020
3.0.13 473,685 7/2/2020
3.0.2 232,638 6/24/2020
3.0.1 3,264 6/23/2020
3.0.0 194,449 6/9/2020
3.0.0-alpha.173.g87fa6ea775 579 6/2/2020
3.0.0-alpha.155 5,660 6/8/2020
3.0.0-alpha.154 562 6/8/2020
3.0.0-alpha.152 447 6/5/2020
3.0.0-alpha.150 601 5/29/2020
3.0.0-alpha.143 19,856 4/5/2020
3.0.0-alpha.133 27,635 1/26/2020
3.0.0-alpha.128 17,523 12/10/2019
3.0.0-alpha.122 65,540 10/29/2019
3.0.0-alpha.103 10,660 10/18/2019
3.0.0-alpha.91 11,088 10/14/2019