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
outputStreamStreamThe 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
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
byteLengthintThe 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
integerValuelongThe 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
stringValuestringThe 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
valueboolThe 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
valuebyte[]The byte sequence to write to the stream.
offsetintThe starting index of the sequence.
lengthintThe length of the sequence.
Write(double)
Writes a 64-bit CBOR floating point to the stream.
public void Write(double value)
Parameters
valuedoubleThe 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
valuelongThe 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
valuefloatThe 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
valuestringThe 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
lengthintThe 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
lengthintThe 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.