System.Formats.Cbor 10.0.0-preview.7.25380.108
About
Provides support for reading and writing values in Concise Binary Object Representation (CBOR) format, as originally defined in IETF RFC 7049.
Key Features
- Reader and writer types for the CBOR format.
- Built-in support for different CBOR conformance modes.
How to Use
Write and read primitives:
using System.Formats.Cbor;
var cborWriter = new CborWriter(CborConformanceMode.Lax);
cborWriter.WriteTextString("Hello World");
var cborReader = new CborReader(cborWriter.Encode(), CborConformanceMode.Lax);
Console.WriteLine(cborReader.ReadTextString());
// Hello World
Write and read an array:
var cborWriter = new CborWriter(CborConformanceMode.Lax);
cborWriter.WriteStartArray(5);
for (var index = 0; index < 5; index++)
{
cborWriter.WriteInt32(index);
}
cborWriter.WriteEndArray();
var cborReader = new CborReader(cborWriter.Encode(), CborConformanceMode.Lax);
var arrayLength = cborReader.ReadStartArray();
for (var index = 0; index < arrayLength; index++)
{
Console.Write(cborReader.ReadInt32());
}
// 01234
cborReader.ReadEndArray();
Inspect writer and reader state:
var cborWriter = new CborWriter(CborConformanceMode.Lax);
cborWriter.WriteTextString("SomeArray");
Console.WriteLine(cborWriter.BytesWritten);
// 10
Console.WriteLine(cborWriter.IsWriteCompleted);
// True
var cborReader = new CborReader(cborWriter.Encode(), CborConformanceMode.Lax);
Console.WriteLine(cborReader.BytesRemaining);
// 10
Console.WriteLine(cborReader.ReadTextString());
// SomeArray
Console.WriteLine(cborReader.BytesRemaining);
// 0
Main Types
The main types provided by this library are:
System.Formats.Cbor.CborReaderSystem.Formats.Cbor.CborWriterSystem.Formats.Cbor.CborReaderStateSystem.Formats.Cbor.CborConformanceModeSystem.Formats.Cbor.CborContentExceptionSystem.Formats.Cbor.CborTag
Additional Documentation
Feedback & Contributing
System.Formats.Cbor is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
https://go.microsoft.com/fwlink/?LinkID=799421
.NET Framework 4.6.2
- Microsoft.Bcl.HashCode (>= 6.0.0)
- System.ValueTuple (>= 4.6.1)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
- System.Memory (>= 4.6.3)
- System.Buffers (>= 4.6.1)
.NET Standard 2.0
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
- System.Memory (>= 4.6.3)
- System.Buffers (>= 4.6.1)
- Microsoft.Bcl.HashCode (>= 6.0.0)
.NET 10.0
- No dependencies.
.NET 9.0
- No dependencies.
.NET 8.0
- No dependencies.