All Projects → dahomey-technologies → Dahomey.Cbor

dahomey-technologies / Dahomey.Cbor

Licence: MIT License
High-performance CBOR (RFC 7049) serialization framework for .Net (C#)

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Dahomey.Cbor

Borer
Efficient CBOR and JSON (de)serialization in Scala
Stars: ✭ 131 (+178.72%)
Mutual labels:  serialization, cbor
Json
JSON for Modern C++
Stars: ✭ 27,824 (+59100%)
Mutual labels:  cbor, rfc-7049
SwiftCBOR
A CBOR implementation for Swift
Stars: ✭ 95 (+102.13%)
Mutual labels:  serialization, cbor
Kotlinx.serialization
Kotlin multiplatform / multi-format serialization
Stars: ✭ 3,550 (+7453.19%)
Mutual labels:  serialization, cbor
Libcbor
CBOR protocol implementation for C
Stars: ✭ 215 (+357.45%)
Mutual labels:  serialization, cbor
Cbor
CBOR RFC 7049 (Go/Golang) - safe & fast with standard API + toarray & keyasint, CBOR tags, float64/32/16, fuzz tested.
Stars: ✭ 250 (+431.91%)
Mutual labels:  serialization, cbor
cbor-d
Concise Binary Object Representation (CBOR) binary data format for D language
Stars: ✭ 20 (-57.45%)
Mutual labels:  serialization, cbor
protodata
A textual language for binary data.
Stars: ✭ 35 (-25.53%)
Mutual labels:  serialization
laravel5-jsonapi-dingo
Laravel5 JSONAPI and Dingo together to build APIs fast
Stars: ✭ 29 (-38.3%)
Mutual labels:  serialization
QSerializer
This repo for Qt/C++ serialization objects in JSON or XML based on QtCore
Stars: ✭ 33 (-29.79%)
Mutual labels:  serialization
cbor-php
CBOR Encoder/Decoder for PHP
Stars: ✭ 27 (-42.55%)
Mutual labels:  cbor
fuser
Header-only library for automatic (de)serialization of C++ types to/from JSON.
Stars: ✭ 48 (+2.13%)
Mutual labels:  serialization
AvroConvert
Apache Avro serializer for .NET
Stars: ✭ 44 (-6.38%)
Mutual labels:  serialization
Enzyme
An experimental .NET asymmetric serializer, designed for write-heavy enviroments with a synchronous flow.
Stars: ✭ 19 (-59.57%)
Mutual labels:  serialization
ocaml-pb-plugin
A protoc plugin for generating OCaml code from protobuf (.proto) files.
Stars: ✭ 18 (-61.7%)
Mutual labels:  serialization
dataconf
Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.
Stars: ✭ 40 (-14.89%)
Mutual labels:  serialization
moonwlker
Jackson JSON without annotation.
Stars: ✭ 14 (-70.21%)
Mutual labels:  serialization
knuckles
👊 High performance cached object serialization
Stars: ✭ 67 (+42.55%)
Mutual labels:  serialization
nimpb
Protocol Buffers for Nim
Stars: ✭ 29 (-38.3%)
Mutual labels:  serialization
sbp
Structured Bindings Pack - serialize C++ structs into MessagePack binary form
Stars: ✭ 16 (-65.96%)
Mutual labels:  serialization

Dahomey.Cbor

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

Nuget (with prereleases) License

Supported .NET versions

  • .NET Standard 2.0
  • .NET Core 3.1
  • .NET 5.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

Installation

NuGet

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

Install-Package Dahomey.Cbor

Compilation from source

  1. dotnet restore
  2. dotnet pack -c Release

How to use Dahomey.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 Dahomey.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. An example can be found here: https://github.com/dahomey-technologies/Dahomey.Cbor/blob/master/src/Dahomey.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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].