Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any .NET implementation of Concise Binary Object Representation(CBOR)?

I'm on the look-out for any implementations of this new binary data representation.

like image 214
redcalx Avatar asked Jul 15 '26 12:07

redcalx


2 Answers

You can try the .Net 5.0 Extension provided by MS

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

https://www.nuget.org/packages/System.Formats.Cbor/5.0.0

https://learn.microsoft.com/en-us/dotnet/api/system.formats.cbor

https://github.com/dotnet/performance/search?q=cbor

Here you have an sample to write and read:

using System;
using System.Formats.Cbor;

var writer = new CborWriter();
        
writer.WriteStartArray(3);
writer.WriteInt64(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
writer.WriteInt32(1);
writer.WriteStartArray(1);
writer.WriteInt32(9);
writer.WriteEndArray();
writer.WriteEndArray();
        
var myByteArray = writer.Encode();
    
    
var reader = new CborReader(data);
    
reader.ReadStartArray();
long unixDT = reader.ReadInt64();
int myInt = reader.ReadInt32();
reader.ReadStartArray();
int myInt2 = reader.ReadInt32();
reader.ReadEndArray();
reader.ReadEndArray();
    
var response = new object[]
    {
        unixDT,
        myInt,
        new object[] { myInt2 }
    };

Cheers

like image 95
André Pedroso Avatar answered Jul 17 '26 16:07

André Pedroso


A list of several CBOR implementations can be found at http://cbor.io — this includes a C# implementation.

like image 45
cabo Avatar answered Jul 17 '26 18:07

cabo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!