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