CborSerializer 1.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package CborSerializer --version 1.0.7                
NuGet\Install-Package CborSerializer -Version 1.0.7                
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="CborSerializer" Version="1.0.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CborSerializer --version 1.0.7                
#r "nuget: CborSerializer, 1.0.7"                
#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.
// Install CborSerializer as a Cake Addin
#addin nuget:?package=CborSerializer&version=1.0.7

// Install CborSerializer as a Cake Tool
#tool nuget:?package=CborSerializer&version=1.0.7                

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. This package has no dependencies.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.0.10 2,658 5/3/2021
1.0.9 256 5/3/2021
1.0.8 254 5/3/2021
1.0.7 262 5/3/2021
1.0.6 274 5/3/2021