Class CBORDecoder
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intCBORDecoder(InputStream, int, int)optionsflag.static final intCBORDecoder(InputStream, int, int)optionsflag.static final intCBORDecoder(InputStream, int, int)optionsflag. -
Constructor Summary
ConstructorsConstructorDescriptionCBORDecoder(byte[] cbor, int options) Create a customized CBOR decoder.CBORDecoder(InputStream inputStream, int options, int maxInputLength) Create a customized CBOR decoder. -
Method Summary
Modifier and TypeMethodDescriptionstatic CBORObjectdecode(byte[] cbor) Decode CBOR data.Decode CBOR data with options.intGet CBOR decoder byte count.
-
Field Details
-
SEQUENCE_MODE
public static final int SEQUENCE_MODECBORDecoder(InputStream, int, int)optionsflag.- See Also:
-
LENIENT_MAP_DECODING
public static final int LENIENT_MAP_DECODINGCBORDecoder(InputStream, int, int)optionsflag.- See Also:
-
LENIENT_NUMBER_DECODING
public static final int LENIENT_NUMBER_DECODINGCBORDecoder(InputStream, int, int)optionsflag.- See Also:
-
-
Constructor Details
-
CBORDecoder
Create a customized CBOR decoder.Note that irrespective of options, the decoder maintains parsed data in the form required for Deterministic Encoding.
This constructor presumes that the actual decoding is performed by one or more (for sequences only) calls to
decodeWithOptions().Customization is provided through an
optionsparameter. Multiple options can be combined using the binary OR-operator ("|"). A zero (0) sets the decoder default mode. The options are defined by the following constants:If theSEQUENCE_MODEoption is defined, the following apply:- The decoder returns after having decoded a single CBOR object, while preparing for the next object.
- If no data is found (EOF),
nullis returned (empty sequences are permitted).
See alsoCBORArray.encodeAsSequence().By default, the decoder requires that CBOR maps conform to the Deterministic Encoding rules.TheLENIENT_MAP_DECODINGoption makes the decoder accept CBOR maps with arbitrary key ordering. Note that duplicate keys still cause aCBORExceptionto be thrown.By default, the decoder requires that CBOR numbers conform to the Deterministic Encoding rules.TheLENIENT_NUMBER_DECODINGoption makes the decoder accept different representations of CBORint,bigint, andfloatitems, only limited by RFC 8949.Exceeding
maxInputLengthduring decoding throws aCBORException. It is recommendable setting this as low as possible, since malformed CBOR objects may request any amount of memory.- Parameters:
inputStream- Stream holding CBOR data.options- The decoder options.maxInputLength- Upper limit in bytes.- Throws:
CBORException- See Also:
-
CBORDecoder
public CBORDecoder(byte[] cbor, int options) Create a customized CBOR decoder. This constructor is identical to:CBORDecoder(new ByteArrayInputStream(cbor), 0, cbor.length);
- Parameters:
cbor- CBOR binary dataoptions- The decoder options.- Throws:
CBORException- See Also:
-
-
Method Details
-
decodeWithOptions
Decode CBOR data with options.Unsupported or malformed CBOR data cause a
CBORExceptionto be thrown.- Returns:
CBORObjectornull(for EOF sequences only).- Throws:
CBORException
-
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.
-
decode
Decode CBOR data. This conveniance method is identical to:new CBORDecoder(new ByteArrayInputStream(cbor), 0, cbor.length) .decodeWithOptions();- Parameters:
cbor- CBOR binary data holding exactly one CBOR object.- Returns:
CBORObject- Throws:
CBORException
-