Class CBORDecoder
-
Constructor Summary
ConstructorDescriptionCBORDecoder
(InputStream inputStream) Create a CBOR decoder supporting options. -
Method Summary
Modifier and TypeMethodDescriptionstatic CBORObject
decode
(byte[] cbor) Decode CBOR data.Decode CBOR data with options.int
Get CBOR decoder byte count.setDeterministicMode
(boolean enforce) Set CBOR decoder deterministic mode.setInputLength
(int maxLength) Set CBOR decoder input max length.setNaNSupport
(boolean accept) Set CBOR decoderNaN/Infinity
support.setSequenceMode
(boolean sequence) Set CBOR decoder sequence mode.
-
Constructor Details
-
CBORDecoder
Create a CBOR decoder supporting options.See
setDeterministicMode(boolean)
,setInputLength(int)
,setNaNSupport(boolean)
, andsetSequenceMode(boolean)
To be used with
decodeWithOptions()
.- Parameters:
inputStream
- Stream holding CBOR data.
-
-
Method Details
-
decodeWithOptions
Decode CBOR data with options.- Returns:
CBORObject
ornull
(for EOF sequences only).- Throws:
CBORException
- For decoding errors.
-
getByteCount
public int getByteCount()Get CBOR decoder byte count.This is equivalent to the position of the next item to be read.
- Returns:
- The number of bytes read so far.
-
setInputLength
Set CBOR decoder input max length.By default the CBOR decoder accepts up to (
Integer.MAX_VALUE
bytes of input data. Since malformed CBOR objects can request arbitrary amounts of memory, it is highly recommended to select a value that is adapted to the actual application. This method enables overriding the default.- Parameters:
maxLength
- Maximum length of CBOR input in bytes. Exceeding this limit will cause aCBORException
to be thrown.- Returns:
this
(updatedCBORDecoder
object)
-
setNaNSupport
Set CBOR decoderNaN/Infinity
support.By default the decoder supports
NaN
,Infinity
, and-Infinity
. In case these variants are not applicable for the application in question, this method enables overriding the default.- Parameters:
accept
- If theaccept
flag is set tofalse
, the mentioned exceptional floating point values will (if encountered), cause aCBORException
to be thrown.- Returns:
this
(updatedCBORDecoder
object)
-
setDeterministicMode
Set CBOR decoder deterministic mode.By default the decoder assumes that CBOR data conforms to the Deterministic Encoding rules. This method enables overriding the default.
- Parameters:
enforce
- If theenforce
flag is set tofalse
, the decoder will accept CBOR data that does not adhere to the map sorting and preferred number serialization requirements. This option may be needed for dealing with "legacy" CBOR implementations. Note: duplicate keys and other invalid (or not supported) CBOR constructs will still cause aCBORException
to be thrown.- Returns:
this
(updatedCBORDecoder
object)
-
setSequenceMode
Set CBOR decoder sequence mode.By default the decoder assumes that CBOR data constitutes of a single CBOR object. This method enables overriding the default.
Also see
CBORSequenceBuilder
.- Parameters:
sequence
- If thesequence
flag is set totrue
, the following apply:- Immediately return after decoding a CBOR object, while preparing the
decoder for the next item.
See also
getByteCount()
. - If no data is found (EOF),
null
is returned (empty sequences are permitted). - Note that data succeeding a just decoded CBOR object is not verified for correctness.
- Immediately return after decoding a CBOR object, while preparing the
decoder for the next item.
See also
- Returns:
this
(updatedCBORDecoder
object)
-
decode
Decode CBOR data.This conveniance method is identical to:
new CBORDecoder(new ByteArrayInputStream(cbor)) .setInputLength(cbor.length) .decodeWithOptions();
- Parameters:
cbor
- CBOR binary data holding exactly one CBOR object.- Returns:
CBORObject
- Throws:
CBORException
- For decoding errors.
-