Class Codec
Wire formats and metered-link packing.
public static class Codec
- Inheritance
-
Codec
- Inherited Members
Remarks
The core's codec trait is generic over the value it carries and cannot cross the C ABI, so what is offered here is the concrete work a caller with an untyped document needs: moving it between JSON and CBOR, and packing a batch of samples small enough for a link that charges per byte.
Methods
CborToJson(ReadOnlySpan<byte>)
Converts a CBOR document into its JSON encoding.
public static byte[] CborToJson(ReadOnlySpan<byte> cbor)
Parameters
cborReadOnlySpan<byte>The CBOR document to convert.
Returns
- byte[]
The UTF-8 JSON encoding.
Exceptions
- PamojaException
The document is malformed, or holds a construct with no JSON equivalent such as a non-string map key.
JsonToCbor(ReadOnlySpan<byte>)
Converts a JSON document into its CBOR encoding.
public static byte[] JsonToCbor(ReadOnlySpan<byte> json)
Parameters
jsonReadOnlySpan<byte>The UTF-8 JSON document to convert.
Returns
- byte[]
The CBOR encoding, typically a good deal smaller.
Exceptions
- PamojaException
The document is not valid JSON.
PackSamples(ReadOnlySpan<long>)
Delta-encodes a series of integer samples into a compact buffer.
public static byte[] PackSamples(ReadOnlySpan<long> samples)
Parameters
samplesReadOnlySpan<long>The samples, in order.
Returns
- byte[]
The packed encoding.
Exceptions
- PamojaException
The native call failed.
TakeBytes(nint)
Copies a native byte buffer out and releases it.
public static byte[] TakeBytes(nint buffer)
Parameters
buffernintThe buffer handle a native call produced.
Returns
- byte[]
The buffer's contents.
UnpackSamples(ReadOnlySpan<byte>)
Unpacks a buffer produced by PackSamples(ReadOnlySpan<long>).
public static long[] UnpackSamples(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>The packed encoding.
Returns
- long[]
The samples, in order.
Exceptions
- PamojaException
The buffer is malformed.