SAIB.Cbor 3.2.0

dotnet add package SAIB.Cbor --version 3.2.0
                    
NuGet\Install-Package SAIB.Cbor -Version 3.2.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="SAIB.Cbor" Version="3.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SAIB.Cbor" Version="3.2.0" />
                    
Directory.Packages.props
<PackageReference Include="SAIB.Cbor" />
                    
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 SAIB.Cbor --version 3.2.0
                    
#r "nuget: SAIB.Cbor, 3.2.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 SAIB.Cbor@3.2.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=SAIB.Cbor&version=3.2.0
                    
Install as a Cake Addin
#tool nuget:?package=SAIB.Cbor&version=3.2.0
                    
Install as a Cake Tool

SAIB.Cbor

High-performance CBOR serialization framework for .Net (C#)

Fork of Dahomey.Cbor by Dahomey Technologies.

Nuget (with prereleases) alternate text is missing from this package README image License

Supported .NET versions

  • .NET 11.0 (net11.0) — SAIB.Cbor 3.2.0

Features

  • Serialization/Deserialization from/to Streams, byte buffer
  • Object Model
  • Mapping to any .Net class
  • Extensible Polymorphism support based on discriminator conventions
  • Extensible Naming conventions
  • Custom converters for not supported types
  • Can require properties or fields with different policies (CborRequiredAttribute)
  • Conditional Property Serialization support based on the existence of a method ShouldSerialize[PropertyName]()
  • Support for interfaces and abstract classes
  • Support for non default constructors, factories and more advanced creator mappings
  • Can ignore default values
  • Object mapping to programmatically configure features on a class
  • Support for serialization callbacks (before/after serialization/deserialization)
  • Support for anonymous types
  • Support for Nullables
  • Support for collection interfaces: IList<>, ICollection<>, IEnumerable<>, IReadOnlyList<>, IReadOnlyCollection<>
  • Support for dynamics
  • Support for structs
  • Support for indefinite-length byte strings (RFC 8949)

CborException.Offset exposes reader error positions. SkipDataItem() is iterative and unbounded by default; use SkipDataItem(int maxDepth) for an explicit limit. Compared with 2.0.0, malformed breaks and reserved primitive headers 0xFD/0xFE are rejected. Nested tags, simple-value payloads and indefinite text strings are skipped correctly. CountingBufferWriter counts encoded bytes using reusable scratch memory; Reset retains its grown capacity.

Installation

NuGet

https://www.nuget.org/packages/SAIB.Cbor/

Install-Package SAIB.Cbor

Compilation from source

  1. dotnet restore src/SAIB.Cbor.sln
  2. dotnet pack src/SAIB.Cbor -c Release

Tests

Build and run the xUnit v3 suite with the .NET 11 SDK and Microsoft.Testing.Platform:

dotnet build src/SAIB.Cbor.sln -c Release -m:8 -warnaserror
dotnet test --project src/SAIB.Cbor.Tests -c Release --no-build --no-restore --max-parallel-test-modules 8 --coverlet --results-directory src/SAIB.Cbor.Tests/bin/TestResults

Coverage reports are written to the results directory. To select tests, add --filter-class SAIB.Cbor.Tests.CborReaderTests. Tests run through Microsoft.Testing.Platform with dotnet test or the test executable.

How to use SAIB.Cbor

Deserialization

Any C# class be deserialized from a CBOR buffer Stream:

class CustomObject
{
  ...
}

CustomObject customObject = await Cbor.DeserializeAsync<CustomObject>(stream);

Another option consists in using SAIB.Cbor object model to deserialize the buffer in a more generic CborObject object:

CborObject cborObject = await Cbor.DeserializeAsync<CborObject>(stream);

Serialization

Any C# class can be serialized to CBOR buffer Stream:

CustomObject customObject = new CustomObject
{
  ...
};

await Cbor.SerializeAsync(customObject, stream);

As for deserialization a more generic solution consists in using CborObject object:

CborObject obj = new CborObject
{
    ["string"] = "foo",
    ["number"] = 12.12,
    ["bool"] = true,
    ["null"] = null,
    ["array"] = new CborArray {1, 2},
    ["object"] = new CborObject { [ "id" ] = 1 },
};

await Cbor.SerializeAsync(cborObject, stream);

Custom converters

If you need to write a customer converter for a specific class, you can inherit a custom converter class for CborConverterBase<T>. An example can be found here: https://github.com/SAIB-Inc/SAIB.Cbor/blob/master/src/SAIB.Cbor.Tests/GuidConverter.cs

Then you can register you custom converter in 3 ways.

  1. Either you decorate your class with the CborConverterAttribute:
[CborConverter(typeof(CustomObjectConverter))]
class CustomObject
{
}
  1. Or you can register your custom converter manually:
CborOptions.Default.Registry.ConverterRegistry.RegisterConverter(typeof(CustomObject), new CustomObjectConverter());
  1. The last option is to decorate a property or a field with the CborConverterAttribute in a class referencing your custom class:
class CustomObject2
{
    [CborConverter(typeof(CustomObjectConverter))]
    public CustomObject CustomObject { get; set; }
}

The last two options are useful when you write a custom cbor converter for a class you can't decorate with the CborConverterAttribute because you don't own it like the above example with System.Guid.

CborConverters are use in the heart of the library for standard types and auto discovered custom classes by reflection. It means you will benefit of the same features and performance.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net11.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SAIB.Cbor:

Package Downloads
Chrysalis

Package Description

Chrysalis.Codec

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.0 0 12/3/2026
2.0.0 1,211 3/2/2026
1.26.2 459 3/2/2026