Class CBORWriter

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

Inheritance
System.Object
CBORWriter
Namespace: PushTechnology.ClientInterface.IO.CBOR
Assembly: Diffusion.Client.dll
Syntax
public sealed class CBORWriter : object
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.

Declaration
public CBORWriter(Stream outputStream)
Parameters
Type Name Description
Stream outputStream

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.

Properties

BaseStream

Returns the underlying stream.

Declaration
public Stream BaseStream { get; }
Property Value
Type Description
Stream

The underlying stream.

Methods

Flush()

Causes any buffered data to be written to the stream.

Declaration
public void Flush()

GetEncodedByteSize(Int32)

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

Declaration
public static int GetEncodedByteSize(int byteLength)
Parameters
Type Name Description
System.Int32 byteLength

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

Returns
Type Description
System.Int32

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

GetEncodedIntegerSize(Int64)

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

Declaration
public static int GetEncodedIntegerSize(long integerValue)
Parameters
Type Name Description
System.Int64 integerValue

The integer value to be encoded in CBOR.

Returns
Type Description
System.Int32

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.

Declaration
public static int GetEncodedStringSize(string stringValue)
Parameters
Type Name Description
System.String stringValue

The string value to be encoded in CBOR.

Returns
Type Description
System.Int32

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

Write(Boolean)

Writes a CBOR boolean to the stream.

Declaration
public void Write(bool value)
Parameters
Type Name Description
System.Boolean value

The boolean value to write to the stream.

Write(Byte[], Int32, Int32)

Writes a sequence of bytes to the stream.

Declaration
public void Write(byte[] value, int offset, int length)
Parameters
Type Name Description
System.Byte[] value

The byte sequence to write to the stream.

System.Int32 offset

The starting index of the sequence.

System.Int32 length

The length of the sequence.

Write(Double)

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

Declaration
public void Write(double value)
Parameters
Type Name Description
System.Double value

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

Write(Int64)

Writes a CBOR integer to the stream.

Declaration
public void Write(long value)
Parameters
Type Name Description
System.Int64 value

The integer value to write to the stream.

Remarks

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

Write(Single)

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

Declaration
public void Write(float value)
Parameters
Type Name Description
System.Single value

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

Write(String)

Writes a CBOR string value to the stream.

Declaration
public void Write(string value)
Parameters
Type Name Description
System.String value

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.

Declaration
public void WriteArray()
Remarks

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

WriteArray(Int32)

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

Declaration
public void WriteArray(int length)
Parameters
Type Name Description
System.Int32 length

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.

Declaration
public void WriteBreak()

WriteIndefiniteBytes()

Writes an indefinite length byte sequence to the stream.

Declaration
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.

Declaration
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.

Declaration
public void WriteNull()

WriteObject()

Writes an indefinite length CBOR object to the stream.

Declaration
public void WriteObject()
Remarks

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

WriteObject(Int32)

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

Declaration
public void WriteObject(int length)
Parameters
Type Name Description
System.Int32 length

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.

Back to top