SofaBuffers Logo

SofaBuffers C# — API documentation

A dependency-free, allocation-light, streaming C# implementation of the SofaBuffers (Sofab) serialization format. It is the runtime stream core (equivalent to the C corelib's istream / ostream), a port of the C corelib (istream.c / ostream.c).

The decoder uses the visitor pattern, so a generated message is typically a single switch over the field id.

Where to start

Quick example

using sofab;

// encode
byte[] buf = new byte[64];
var os = new OStream(buf);
os.WriteUnsigned(1, 42);
os.WriteSigned(2, -7);
os.WriteString(3, "hi");
int used = os.BytesUsed;

// decode
class My : IVisitor
{
    public ulong A;
    public long B;
    public void Unsigned(int id, ulong v) { if (id == 1) A = v; }
    public void Signed(int id, long v)    { if (id == 2) B = v; }
}
var sink = new My();
new IStream().Feed(buf, 0, used, sink);

See the project README for the full guide, benchmarks and the wire-format documentation links.