ChosenFewSoftware.SnabNet.SourceGenerators 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package ChosenFewSoftware.SnabNet.SourceGenerators --version 1.0.4
                    
NuGet\Install-Package ChosenFewSoftware.SnabNet.SourceGenerators -Version 1.0.4
                    
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="ChosenFewSoftware.SnabNet.SourceGenerators" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ChosenFewSoftware.SnabNet.SourceGenerators" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="ChosenFewSoftware.SnabNet.SourceGenerators" />
                    
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 ChosenFewSoftware.SnabNet.SourceGenerators --version 1.0.4
                    
#r "nuget: ChosenFewSoftware.SnabNet.SourceGenerators, 1.0.4"
                    
#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 ChosenFewSoftware.SnabNet.SourceGenerators@1.0.4
                    
#: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=ChosenFewSoftware.SnabNet.SourceGenerators&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=ChosenFewSoftware.SnabNet.SourceGenerators&version=1.0.4
                    
Install as a Cake Tool

CFS.SnabNet

.NET NuGet

SnabNet, also known as SNAB.NET is a barebones, no nonsense implementation of the SNAB generalized bitstream format for efficient, low-overhead, high-performance serialization with support for multiple programming languages and cross-platform scenarios. Importantly, this implementation supports all official versions of the original specification and includes goodies for parsing and serializing arbitrary data in a flexible fashion.

Features

Key features of SNAB that are fully functional in SnabNet are listed as follows:

  • Parsing / serializing little AND big endian bitstreams
  • SNAB compression (via zlib deflate)
  • Bitstream validation based on crc32 checksum and length fields
  • Registering custom datatypes for extensible parsing / serialization

Other key library features that are implementation-specific include the following:

  • Source generation for serialization of custom C# types
  • Unit tests for specification coverage and overall correctness
  • Support for ExpandoObject for both parsing and serialization

How to Use

CFS.SnabNet is available as two NuGet packages:

  1. ChosenFewSoftware.SnabNet
  2. ChosenFewSoftware.SnabNet.SourceGenerators

The former includes all basic functionality for serializing and deserializing weakly typed instances. The latter package includes source generators for mapping SNAB data onto strongly typed instances. Example code for both parsing and serializing custom data types is written in the sections below.

SnabInstance (Type Registration)

using CFS.SnabNet;

/* Somewhere in your application code */
public class CustomType : ISnabType 
{
    public const byte TypeId = 0x80;
    
    public HashSet<byte> TypeIds { get; }
    
    public CustomType() 
    {
        TypeIds = new() { TypeId }
    }
    
    public object? ReadFromInstance(SnabReader instance, byte typeId) 
    {
        /* Your implementation goes here */
    }
    
    public void WriteToInstance(SnabWriter instance, byte typeId, object? obj) 
    {
        /* Your implementation goes here */
    }
}

/* Later, where you want to use it */
SnabInstance instance = new();
instance.RegisterType<CustomType>();

/* Continue with next examples for reading and writing */

SnabReader (Deserialization)

using CFS.SnabNet;

SnabInstance instance = new();
/* Register custom types here */

dynamic parsedData;
using (SnabReader reader = instance.CreateReader(/* Stream with your data */)) 
{
    /* Grab data as ExpandoObject */
    parsedData = reader.Deserialize();
}

/* Grab data from arbitrary fields based on what you expect */
int intData = parsedData.int_field;
string strData = parsedData.string_field;

SnabWriter (Serialization)

using System.Dynamic; /* for ExpandoObject */
using CFS.SnabNet;

/* Input data can be ExpandoObject or specific class instance (see next example) */
dynamic dataObject = new ExpandoObject();
dataObject.int_field = 42;
dataObject.real_field = 3.1415;

SnabInstance instance = new();
/* Register custom types here */

using (SnabWriter writer = instance.CreateWriter(/* Stream to write data to */, SnabFlags.None)) 
{
    writer.Serialize(dataObject);
}

ISnabStruct (Source Generation)

using CFS.SnabNet;
using CFS.SnabNet.SourceGeneration;

/* Mark this type for source generation, make sure to mark as "partial" */
[SnabStruct]
public partial class TestStruct 
{
    /* Declare property for serialization 
    (parameters optional, but recommended) */
    [SnabField("int_field", SnabType.Integer)]
    public int IntField { get; set; }
    
    /* ... */
}

/* Later, to use... */
SnabInstance instance = new();

/* For serialization */
using(SnabWriter writer = instance.CreateWriter(/* ... */))
{
    writer.Serialize(new TestStruct { /* ... */ });
}

/* For deserialization */
TestStruct parsedData;
using (SnabReader reader = instance.CreateReader(/* ... */))
{
    parsedData = reader.Deserialize<TestStruct>();
}

Development Guide

Ensure that you have Git and .NET SDK 8.0 or higher installed and run the following commands to get started:

# Grab source from GitHub repository
git clone "https://github.com/IsaMorphic/CFS.SnabNet.git"
cd ".\CFS.SnabNet"

# Full rebuild of solution
dotnet build --no-incremental

# Run all unit tests
dotnet test --no-build

Special Thanks

Special thanks to AlubJ for coordinating the SNAB standard, and to my partner Hazel for putting up with me ❤️

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 was computed. 
.NET Framework net461 was computed.  net462 was computed.  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.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 109 3/24/2026
1.0.4 95 3/24/2026
1.0.3 95 3/24/2026
1.0.2 99 3/24/2026
1.0.1 103 3/24/2026
1.0.0 102 3/12/2026