Class CborDecoder
java.lang.Object
com.pnfsoftware.jeb.util.encoding.cbor.CborDecoder
Provides a decoder capable of handling CBOR encoded data from a
InputStream.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected longexpectIntegerType(int ib) Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.peekType()Peeks in the input stream for the upcoming type.longProlog to reading an array value in CBOR format.booleanReads a boolean value in CBOR format.Reads a "break"/stop value in CBOR format.byte[]Reads a byte string value in CBOR format.longProlog to reading a byte string value in CBOR format.doubleReads a double-precision float value in CBOR format.floatReads a single-precision float value in CBOR format.doubleReads a half-precision float value in CBOR format.longreadInt()Reads a signed or unsigned integer value in CBOR format.intReads a signed or unsigned 16-bit integer value in CBOR format.longReads a signed or unsigned 32-bit integer value in CBOR format.longReads a signed or unsigned 64-bit integer value in CBOR format.intreadInt8()Reads a signed or unsigned 8-bit integer value in CBOR format.protected intreadMajorType(int majorType) Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.protected voidreadMajorTypeExact(int majorType, int subtype) Reads the next major type from the underlying input stream, and verifies whether it matches the given expectations.protected longreadMajorTypeWithSize(int majorType) Reads the next major type from the underlying input stream, verifies whether it matches the given expectation, and decodes the payload into a size.longProlog to reading a map of key-value pairs in CBOR format.readNull()Reads anull-value in CBOR format.byteReads a single byte value in CBOR format.intReads a signed or unsigned small (<= 23) integer value in CBOR format.longreadTag()Reads a semantic tag value in CBOR format.Reads an UTF-8 encoded string value in CBOR format.longProlog to reading an UTF-8 encoded string value in CBOR format.protected longreadUInt(int length, boolean breakAllowed) Reads an unsigned integer with a given length-indicator.protected intReads an unsigned 16-bit integer valueprotected longReads an unsigned 32-bit integer valueprotected longReads an unsigned 64-bit integer valueprotected intReads an unsigned 8-bit integer valueprotected longreadUIntExact(int expectedLength, int length) Reads an unsigned integer with a given length-indicator.Reads an undefined value in CBOR format.
-
Field Details
-
m_is
-
-
Constructor Details
-
CborDecoder
Creates a newCborDecoderinstance.- Parameters:
is- the actual input stream to read the CBOR-encoded data from, cannot benull.
-
-
Method Details
-
peekType
Peeks in the input stream for the upcoming type.- Returns:
- the upcoming type in the stream, or
nullin case of an end-of-stream. - Throws:
IOException- in case of I/O problems reading the CBOR-type from the underlying input stream.
-
readArrayLength
Prolog to reading an array value in CBOR format.- Returns:
- the number of elements in the array to read, or -1 in case of infinite-length arrays.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readBoolean
Reads a boolean value in CBOR format.- Returns:
- the read boolean.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readBreak
Reads a "break"/stop value in CBOR format.- Returns:
- always
null. - Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readByteString
Reads a byte string value in CBOR format.- Returns:
- the read byte string, never
null. In case the encoded string has a length of 0, an empty string is returned. - Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readByteStringLength
Prolog to reading a byte string value in CBOR format.- Returns:
- the number of bytes in the string to read, or -1 in case of infinite-length strings.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readDouble
Reads a double-precision float value in CBOR format.- Returns:
- the read double value, values from
Float.MIN_VALUEtoFloat.MAX_VALUEare supported. - Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readFloat
Reads a single-precision float value in CBOR format.- Returns:
- the read float value, values from
Float.MIN_VALUEtoFloat.MAX_VALUEare supported. - Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readHalfPrecisionFloat
Reads a half-precision float value in CBOR format.- Returns:
- the read half-precision float value, values from
Float.MIN_VALUEtoFloat.MAX_VALUEare supported. - Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readInt
Reads a signed or unsigned integer value in CBOR format.- Returns:
- the read integer value, values from
Long.MIN_VALUEtoLong.MAX_VALUEare supported. - Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readInt16
Reads a signed or unsigned 16-bit integer value in CBOR format.- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
-
readInt32
Reads a signed or unsigned 32-bit integer value in CBOR format.- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
-
readInt64
Reads a signed or unsigned 64-bit integer value in CBOR format.- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
-
readInt8
Reads a signed or unsigned 8-bit integer value in CBOR format.- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
-
readMapLength
Prolog to reading a map of key-value pairs in CBOR format.- Returns:
- the number of entries in the map, >= 0.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readNull
Reads anull-value in CBOR format.- Returns:
- always
null. - Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readSimpleValue
Reads a single byte value in CBOR format.- Returns:
- the read byte value.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readSmallInt
Reads a signed or unsigned small (<= 23) integer value in CBOR format.- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
-
readTag
Reads a semantic tag value in CBOR format.- Returns:
- the read tag value.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readTextString
Reads an UTF-8 encoded string value in CBOR format.- Returns:
- the read UTF-8 encoded string, never
null. In case the encoded string has a length of 0, an empty string is returned. - Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readTextStringLength
Prolog to reading an UTF-8 encoded string value in CBOR format.- Returns:
- the length of the string to read, or -1 in case of infinite-length strings.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readUndefined
Reads an undefined value in CBOR format.- Returns:
- always
null. - Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
expectIntegerType
Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.- Parameters:
majorType- the expected major type, cannot benull(unchecked).- Returns:
- either -1 if the major type was an signed integer, or 0 otherwise.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readMajorType
Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.- Parameters:
majorType- the expected major type, cannot benull(unchecked).- Returns:
- the read subtype, or payload, of the read major type.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readMajorTypeExact
Reads the next major type from the underlying input stream, and verifies whether it matches the given expectations.- Parameters:
majorType- the expected major type, cannot benull(unchecked);subtype- the expected subtype.- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readMajorTypeWithSize
Reads the next major type from the underlying input stream, verifies whether it matches the given expectation, and decodes the payload into a size.- Parameters:
majorType- the expected major type, cannot benull(unchecked).- Returns:
- the number of succeeding bytes, >= 0, or -1 if an infinite-length type is read.
- Throws:
IOException- in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
-
readUInt
Reads an unsigned integer with a given length-indicator.- Parameters:
length- the length indicator to use;- Returns:
- the read unsigned integer, as long value.
- Throws:
IOException- in case of I/O problems reading the unsigned integer from the underlying input stream.
-
readUInt16
Reads an unsigned 16-bit integer value- Returns:
- value the read value, values from
Long.MIN_VALUEtoLong.MAX_VALUEare supported. - Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
readUInt32
Reads an unsigned 32-bit integer value- Returns:
- value the read value, values from
Long.MIN_VALUEtoLong.MAX_VALUEare supported. - Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
readUInt64
Reads an unsigned 64-bit integer value- Returns:
- value the read value, values from
Long.MIN_VALUEtoLong.MAX_VALUEare supported. - Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
readUInt8
Reads an unsigned 8-bit integer value- Returns:
- value the read value, values from
Long.MIN_VALUEtoLong.MAX_VALUEare supported. - Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
readUIntExact
Reads an unsigned integer with a given length-indicator.- Parameters:
length- the length indicator to use;- Returns:
- the read unsigned integer, as long value.
- Throws:
IOException- in case of I/O problems reading the unsigned integer from the underlying input stream.
-