Super early and experimental. This is research, published so people can try it, not a product. Expect every API here to change or vanish, and nothing to be supported. It does work, within the narrow limits listed below, and is tested against protobuf-net on every build.
protobuf-net.Zero is Protocol Buffers serialization for C# compiled with no runtime at all: no
base class library, no garbage collector, no exceptions, no reflection. It is in the spirit of
bflat’s --stdlib:zero and
zerosharp: a whole program that serializes
protobuf is a native exe of under 20 KB, importing a handful of kernel32 functions.
It shares protobuf-net’s attribute model: you annotate a struct with [ProtoContract] and
[ProtoMember], and a source generator writes the serializer at compile time. The bytes match
protobuf-net’s exactly.
Two ways to use it
- In a zero app, with no runtime: use the
protobuf-net.Zero.Sdkproject SDK. This is the point of the project. - In an ordinary .NET 10 app: reference
protobuf-net.Zerolike any package. It is the same binary, and on ordinary .NET it simply runs on the real runtime. Useful for sharing contracts between a zero component and everything else, and for testing.
Pages
- Getting started: a complete zero app that writes and reads a message
- Contracts: what you can annotate, and what the generator supports so far
- How it works: what “no runtime” means, and the trick that lets one library binary run in both worlds
Current limits
These are the important ones. Each is a property of the research so far, not a design decision.
- Windows x64 only, built with the .NET 10 SDK and the MSVC build tools.
- The generator writes the write half only. You hand-write the read side, a small
TryMergemethod; Getting started shows one. - A narrow set of types:
int,long(plain or zigzag),uint(varint or fixed32),double,string, nested contract structs, and repeatedintor contract structs. See Contracts. - A zero app is a very small world. No
newfor classes or arrays, no exceptions, no casts on reference types, nostackalloc. Any OS call you need, you declare yourself. See How it works.
Source and feedback
github.com/protobuf-net/protobuf-net.Zero.
The research notes, recording what it took and what went wrong, are in
notes/findings.md.
For protobuf-net itself, see docs.protobuf-net.dev.