ChosenFewSoftware.SnabNet.SourceGenerators
1.0.2
See the version list below for details.
dotnet add package ChosenFewSoftware.SnabNet.SourceGenerators --version 1.0.2
NuGet\Install-Package ChosenFewSoftware.SnabNet.SourceGenerators -Version 1.0.2
<PackageReference Include="ChosenFewSoftware.SnabNet.SourceGenerators" Version="1.0.2" />
<PackageVersion Include="ChosenFewSoftware.SnabNet.SourceGenerators" Version="1.0.2" />
<PackageReference Include="ChosenFewSoftware.SnabNet.SourceGenerators" />
paket add ChosenFewSoftware.SnabNet.SourceGenerators --version 1.0.2
#r "nuget: ChosenFewSoftware.SnabNet.SourceGenerators, 1.0.2"
#:package ChosenFewSoftware.SnabNet.SourceGenerators@1.0.2
#addin nuget:?package=ChosenFewSoftware.SnabNet.SourceGenerators&version=1.0.2
#tool nuget:?package=ChosenFewSoftware.SnabNet.SourceGenerators&version=1.0.2
CFS.SnabNet
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
ExpandoObjectfor both parsing and serialization
How to Use
CFS.SnabNet is available as two NuGet packages:
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 | Versions 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. |
-
.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.