CborSerializer 1.0.10
dotnet add package CborSerializer --version 1.0.10
NuGet\Install-Package CborSerializer -Version 1.0.10
<PackageReference Include="CborSerializer" Version="1.0.10" />
paket add CborSerializer --version 1.0.10
#r "nuget: CborSerializer, 1.0.10"
// Install CborSerializer as a Cake Addin #addin nuget:?package=CborSerializer&version=1.0.10 // Install CborSerializer as a Cake Tool #tool nuget:?package=CborSerializer&version=1.0.10
CborSerializer
Open-ended CBOR serialization for .net5. This is just a thin wrapper around the System.Formats.Cbor namespace to allow for easier serialization of objects. The only dependency is System.Formats.Cbor
.
Usage
Usage is straight-forward.
Declare a class that will be serialized/deserialized:
[CborSerialize(typeof(TestObjectConvertor))]
public class TestObject
{
public int SomeInt { get; }
public string SomeString { get; }
public Tuple<int, bool> SomeTuple { get; }
public TestObject(int someInt, string someString, Tuple<int,bool> someTuple)
{
SomeInt = someInt;
SomeString = someString;
SomeTuple = someTuple;
}
}
Declare a CborConvertor for it:
public class TestObjectConvertor : ICborConvertor<TestObject>
{
public TestObject Read(ref CborReader reader)
{
reader.ReadStartArray();
var someInt = reader.ReadInt32();
var someString = reader.ReadTextString();
// in this example we convert the Tuple to an array, but your implementation
// can be whatever you want
reader.ReadStartArray();
var tupleInt = reader.ReadInt32();
var tupleBool = reader.ReadBoolean();
return new TestObject(someInt, someString, new Tuple<int, bool>(tupleInt, tupleBool));
}
public void Write(ref CborWriter writer, TestObject value)
{
writer.WriteStartArray(2);
writer.WriteInt32(value.SomeInt);
writer.WriteTextString(value.SomeString);
// in this example we convert the Tuple to an array, but your implementation
// can be whatever you want
writer.WriteStartArray(2);
writer.WriteInt32(value.SomeTuple.Item1);
writer.WriteInt32(value.SomeTuple.Item2);
writer.WriteEndArray();
writer.WriteEndArray();
}
}
Converting to/from serialized formats using the static methods:
byte[] serializedPayload = CborConvertor.Serialize(new TestObject());
TestObject deserializedObject = CborConvertor.Deserialize<TestObject>(byteArray);
Automatic Serialization
This library does not implement any type of automatic property mapping/serialization. All serialization must be manually implemented. My use case was a unique wire format and auto-mapping was not a good fit. This allows you to declare any wire format.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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. |
-
net5.0
- System.Formats.Cbor (>= 5.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CborSerializer:
Package | Downloads |
---|---|
SAIB.Cardano.Sync
A ASP.NET Framework for Indexing Cardano Data storing it in PostgresSQL |
|
Argus.Sync
A ASP.NET Framework for Indexing Cardano Data storing it in PostgresSQL |
GitHub repositories
This package is not used by any popular GitHub repositories.