Table of Contents

Class CBORWriter

Namespace
PushTechnology.ClientInterface.IO.CBOR
Assembly
Diffusion.Client.dll

The CBOR writer that is able to write CBOR-encoded data to a stream.

public sealed class CBORWriter
Inheritance
CBORWriter
Inherited Members

Remarks

The output is not validated which allows for illegal CBOR to be created by this writer.

Constructors

CBORWriter(Stream)

Creates a new CBORWriter that is able to write CBOR-encoded data to a given output stream.

public CBORWriter(Stream outputStream)

Parameters

outputStream Stream

The output stream to write CBOR-encoded data to.

Remarks

The reader does not take ownership of the given outputStream. The stream needs to be disposed of if it is no longer needed.

Exceptions

ArgumentNullException

The given stream is null.

ArgumentException

The given stream does not support writing.

Properties

BaseStream

Returns the underlying stream.

public Stream BaseStream { get; }

Property Value

Stream

Methods

Flush()

Causes any buffered data to be written to the stream.

public void Flush()

GetEncodedByteSize(int)

Returns the size of a byte sequence if encoded in CBOR.

public static int GetEncodedByteSize(int byteLength)

Parameters

byteLength int

The length of the byte sequence to be encoded in CBOR.

Returns

int

The size in bytes of the CBOR-encoded byte sequence.

GetEncodedIntegerSize(long)

Returns the size of as an integer if encoded in CBOR.

public static int GetEncodedIntegerSize(long integerValue)

Parameters

integerValue long

The integer value to be encoded in CBOR.

Returns

int

The size in bytes of the CBOR-encoded integer value.

GetEncodedStringSize(string)

Returns the size of a UTF-8 encoded string if encoded in CBOR.

public static int GetEncodedStringSize(string stringValue)

Parameters

stringValue string

The string value to be encoded in CBOR.

Returns

int

The size in bytes of the CBOR-encoded UTF-8 string.

Write(bool)

Writes a CBOR boolean to the stream.

public void Write(bool value)

Parameters

value bool

The boolean value to write to the stream.

Write(byte[], int, int)

Writes a sequence of bytes to the stream.

public void Write(byte[] value, int offset, int length)

Parameters

value byte[]

The byte sequence to write to the stream.

offset int

The starting index of the sequence.

length int

The length of the sequence.

Write(double)

Writes a 64-bit CBOR floating point to the stream.

public void Write(double value)

Parameters

value double

The 64-bit floating point value to write to the stream.

Write(long)

Writes a CBOR integer to the stream.

public void Write(long value)

Parameters

value long

The integer value to write to the stream.

Remarks

The integer gets encoded in the smallest possible data type. See GetEncodedIntegerSize(long) to receive the size of the encoded value.

Write(float)

Writes a 32-bit CBOR floating point to the stream.

public void Write(float value)

Parameters

value float

The 32-bit floating point value to write to the stream.

Write(string)

Writes a CBOR string value to the stream.

public void Write(string value)

Parameters

value string

The string value to write to the stream.

Remarks

The string will be encoded in UTF-8 and can be a string value or a field name for key/value pairs.

WriteArray()

Writes an indefinite length CBOR array to the stream.

public void WriteArray()

Remarks

The array has to be closed by a CBOR Break in order to be valid.

WriteArray(int)

Writes a CBOR array with a specific number of items to the stream.

public void WriteArray(int length)

Parameters

length int

The number of items within the array.

Remarks

This method has to be followed with the exact amount of items specified by the given length in order for the resulting CBOR to be valid.

WriteBreak()

Writes a CBOR Break to the stream that indicates the end of a sequence or structure.

public void WriteBreak()

WriteIndefiniteBytes()

Writes an indefinite length byte sequence to the stream.

public void WriteIndefiniteBytes()

Remarks

The byte sequence has to be followed by a CBOR Break in order to be valid.

WriteIndefiniteString()

Writes an indefinite length CBOR string value to the stream.

public void WriteIndefiniteString()

Remarks

The string sequence has to be followed by a CBOR Break in order to be valid.

WriteNull()

Writes a CBOR 'null' value to the stream.

public void WriteNull()

WriteObject()

Writes an indefinite length CBOR object to the stream.

public void WriteObject()

Remarks

The object has to be closed by a CBOR Break in order to be valid.

WriteObject(int)

Writes a CBOR object with a specific number of key/value pairs to the stream.

public void WriteObject(int length)

Parameters

length int

The number of key/value pairs within the object.

Remarks

This method has to be followed with the exact amount of key/value pairs specified by the given length in order for the resulting CBOR to be valid.