Class CBORReader
The CBOR reader that is able to read CBOR-encoded data from a stream.
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 |
CurrentType
Returns the current CBORType.
Declaration
public CBORType CurrentType { get; }
Property Value
Type | Description |
---|---|
CBORType |
Fieldname
Returns the fieldname asssociated with the current CBORType.
Declaration
public string Fieldname { get; }
Property Value
Type | Description |
---|---|
String |
InArray
Returns true if the reader is currently within an array structure. Otherwise false.
Declaration
public bool InArray { get; }
Property Value
Type | Description |
---|---|
Boolean |
InObject
Returns true if the reader is currently within an object structure. Otherwise false.
Declaration
public bool InObject { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsEndOfStream
Returns true if the reader has reached the end of the stream. Otherwise false.
Declaration
public bool IsEndOfStream { get; }
Property Value
Type | Description |
---|---|
Boolean |
SequenceLength
Returns the length of the current stream sequence.
Declaration
public int SequenceLength { get; }
Property Value
Type | Description |
---|---|
Int32 |
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 |
---|---|
Int32 |
Methods
GetBoolean()
Returns the current CBORType value as a boolean.
Declaration
public bool GetBoolean()
Returns
Type | Description |
---|---|
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 |
---|---|
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 |
---|---|
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 |
---|---|
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 |
---|---|
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 |
---|---|
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. |