Class CBORReader
The CBOR reader that is able to read CBOR-encoded data from a stream.
Inheritance
Namespace: PushTechnology.ClientInterface.IO.CBOR
Assembly: Diffusion.Client.dll
Syntax
public sealed class CBORReader : object
Constructors
CBORReader(Stream)
Creates a new CBORReader that is able to read CBOR-encoded data from a given input stream.
Declaration
public CBORReader(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | inputStream | The input stream to read CBOR-encoded data from. |
Remarks
The reader does not take ownership of the given inputStream.
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. |
CurrentType
Returns the current CBORType.
Declaration
public CBORType CurrentType { get; }
Property Value
| Type | Description |
|---|---|
| CBORType | The current CBORType. |
Fieldname
Returns the fieldname asssociated with the current CBORType.
Declaration
public string Fieldname { get; }
Property Value
| Type | Description |
|---|---|
| System.String | The fieldname asssociated with the current CBORType. |
InArray
Returns true if the reader is currently within an array structure. Otherwise false.
Declaration
public bool InArray { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean | Whether the reader is currently within an array structure. |
InObject
Returns true if the reader is currently within an object structure. Otherwise false.
Declaration
public bool InObject { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean | Whether the reader is currently within an object structure. |
IsEndOfStream
Returns true if the reader has reached the end of the stream. Otherwise false.
Declaration
public bool IsEndOfStream { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean | Whether the reader has reached the end of the stream. |
SequenceLength
Returns the length of the current stream sequence.
Declaration
public int SequenceLength { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The length of the current stream sequence. |
StructureDepth
Returns the depth level of the current structure. A depth of 0 indicates the 'root' level.
Declaration
public int StructureDepth { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The depth level of the current structure. |
Methods
GetBoolean()
Returns the current CBORType value as a boolean.
Declaration
public bool GetBoolean()
Returns
| Type | Description |
|---|---|
| System.Boolean | The current CBORType value as a boolean. |
Exceptions
| Type | Condition |
|---|---|
| CBORException | The value is not a valid boolean type. |
GetBytes()
Returns the current CBORType value as a sequence of bytes.
Declaration
public byte[] GetBytes()
Returns
| Type | Description |
|---|---|
| System.Byte[] | The current CBORType value as a sequence of bytes. |
Remarks
This will return the internal byte array instead of a copy.
Exceptions
| Type | Condition |
|---|---|
| CBORException | The value is not a valid sequence type. |
GetFloatingPoint()
Returns the current CBORType value as a 64-bit floating point.
Declaration
public double GetFloatingPoint()
Returns
| Type | Description |
|---|---|
| System.Double | The current CBORType value as a 64-bit floating point. |
Exceptions
| Type | Condition |
|---|---|
| CBORException | The value is not a valid floating point type. |
GetInteger()
Returns the current CBORType value as a 64-bit signed integer.
Declaration
public long GetInteger()
Returns
| Type | Description |
|---|---|
| System.Int64 | The current CBORType value as a 64-bit signed integer. |
Exceptions
| Type | Condition |
|---|---|
| CBORException | The value is not a valid integer type. |
GetString()
Returns the current CBORType value as a UTF-8 encoded string.
Declaration
public string GetString()
Returns
| Type | Description |
|---|---|
| System.String | The current CBORType value as a UTF-8 encoded string. |
Exceptions
| Type | Condition |
|---|---|
| CBORException | The value is not a valid sequence type. |
GetTag()
Returns the tag value that is associated with the current CBORType.
Declaration
public long GetTag()
Returns
| Type | Description |
|---|---|
| System.Int64 | The tag as a positive 64-bit signed integer value. -1 if the current CBORType has not been preceded by a tag. |
Read(CBORReader, ICBORReaderCallback)
Reads from a CBOR-encoded stream in a visitor-style fashion.
Declaration
public static void Read(CBORReader reader, ICBORReaderCallback callback)
Parameters
| Type | Name | Description |
|---|---|---|
| CBORReader | reader | The reader instance to use for reading operations. |
| ICBORReaderCallback | callback | The callback instance to report the results to. |
ReadNext()
Reads the next CBORType from the input stream.
Declaration
public CBORType ReadNext()
Returns
| Type | Description |
|---|---|
| CBORType | The next CBORType or null if the reader has reached the end of the stream. |
Exceptions
| Type | Condition |
|---|---|
| CBORException | The given data stream is not encoded in valid CBOR. |