Class CBORObject
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
CBORArray
,CBORBigInt
,CBORBoolean
,CBORBytes
,CBORFloat
,CBORInt
,CBORMap
,CBORNull
,CBORString
,CBORTag
In this implementation "object" should be regarded as equivalent to the RFC 8949 "data item".
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks for unread CBOR data.clone()
Deep copy ofCBORObject
.static CBORObject
decode
(byte[] cborData) Decodes CBOR data.static CBORObject
decode
(InputStream inputStream, boolean sequenceFlag, boolean nonDeterministic, Integer maxLength) Decodes CBOR data with options.byte[]
encode()
Encodes CBOR object.boolean
Checks CBOR objects for equality.getArray()
Returnsarray
object.ReturnsBigInteger
value.boolean
Returnsboolean
value.int
getByte()
Returnsbyte
value.byte[]
getBytes()
Returnsbyte string
value.double
Returnsdouble
value.float
getFloat()
Returnsfloat
value.int
getInt()
Returnsint
value.long
getLong()
Returnslong
value.getMap()
Returnsmap
object.int
getShort()
Returnsshort
value.Returnstext string
value.getTag()
Returns tag object.getType()
Returns core CBOR type.int
Returns unsignedbyte
value.long
Returns unsignedint
value.long
Returns unsignedlong
value.int
Returns unsignedshort
value.int
hashCode()
boolean
isNull()
Checks fornull
.scan()
Scans object node and marks as read.toDiagnosticNotation
(boolean prettyPrint) Returns the CBOR object in Diagnostic Notation.toString()
Returns the CBOR object in a pretty-printed form.
-
Method Details
-
getType
Returns core CBOR type.- Returns:
- CBOR core type
-
encode
public byte[] encode()Encodes CBOR object.Note: this method always return CBOR data using Deterministic Encoding.
- Returns:
- CBOR encoded
byteArray
-
getBigInteger
ReturnsBigInteger
value.This method requires that the object is a
CBORBigInt
orCBORInt
, otherwise aCBORException
is thrown.- Returns:
BigInteger
-
getLong
public long getLong()Returnslong
value.This method requires that the object is a
Also seeCBORInt
and fits a Javalong
(Long.MIN_VALUE
toLong.MAX_VALUE
), otherwise aCBORException
is thrown.getBigInteger()
.- Returns:
long
-
getUnsignedLong
public long getUnsignedLong()Returns unsignedlong
value.This method requires that the object is an unsigned
CBORInt
, otherwise aCBORException
is thrown.- Returns:
long
-
getInt
public int getInt()Returnsint
value.This method requires that the object is a
Also seeCBORInt
and fits a Javaint
(Integer.MIN_VALUE
toInteger.MAX_VALUE
), otherwise aCBORException
is thrown.getBigInteger()
.- Returns:
int
-
getUnsignedInt
public long getUnsignedInt()Returns unsignedint
value.This method requires that the object is a
Also seeCBORInt
and fits a Javaint
(0
to0xffffffff
), otherwise aCBORException
is thrown.getBigInteger()
.- Returns:
long
-
getShort
public int getShort()Returnsshort
value.This method requires that the object is a
Also seeCBORInt
and fits a Javashort
(Short.MIN_VALUE
toShort.MAX_VALUE
), otherwise aCBORException
is thrown.getBigInteger()
.- Returns:
int
-
getUnsignedShort
public int getUnsignedShort()Returns unsignedshort
value.This method requires that the object is a
Also seeCBORInt
and fits a Javashort
(0
to0xffff
), otherwise aCBORException
is thrown.getBigInteger()
.- Returns:
int
-
getByte
public int getByte()Returnsbyte
value.This method requires that the object is a
Also seeCBORInt
and fits a Javabyte
(Byte.MIN_VALUE
toByte.MAX_VALUE
), otherwise aCBORException
is thrown.getBigInteger()
.- Returns:
int
-
getUnsignedByte
public int getUnsignedByte()Returns unsignedbyte
value.This method requires that the object is a
Also seeCBORInt
and fits a Javabyte
(0
to0xff
), otherwise aCBORException
is thrown.getBigInteger()
.- Returns:
int
-
getDouble
public double getDouble()Returnsdouble
value.This method requires that the object is a
CBORFloat
, otherwise aCBORException
is thrown.- Returns:
double
-
getFloat
public float getFloat()Returnsfloat
value.This method requires that the object is a
CBORFloat
holding a 16 or 32-bit IEEE 754 value, otherwise aCBORException
is thrown.- Returns:
float
-
getBoolean
public boolean getBoolean()Returnsboolean
value.This method requires that the object is a
CBORBoolean
, otherwise aCBORException
is thrown.- Returns:
boolean
-
isNull
public boolean isNull()Checks fornull
.If the object is a
CBORNull
the call will returntrue
, else it will returnfalse
.Note that the object will only be considered as "read" (
checkForUnread()
) if the object is aCBORNull
.- Returns:
boolean
-
getString
Returnstext string
value.This method requires that the object is a
CBORString
, otherwise aCBORException
is thrown.- Returns:
String
-
getBytes
public byte[] getBytes()Returnsbyte string
value.This method requires that the object is a
CBORBytes
, otherwise aCBORException
is thrown.- Returns:
byteArray
-
getMap
Returnsmap
object.This method requires that the object is a
CBORMap
, otherwise aCBORException
is thrown.- Returns:
- CBOR
map
object
-
getArray
Returnsarray
object.This method requires that the object is a
CBORArray
, otherwise aCBORException
is thrown.- Returns:
- CBOR
array
object
-
getTag
Returns tag object.This method requires that the object is a
CBORTag
, otherwise aCBORException
is thrown.- Returns:
- CBOR
tag
object
-
scan
Scans object node and marks as read.This method sets the status of this object as well as to possible child objects to "read".
Also seecheckForUnread()
.- Returns:
this
-
checkForUnread
public void checkForUnread()Checks for unread CBOR data.Verifies that all data from the current object including possible child objects have been read (through calling
Also seegetBytes()
etc.), and throws aCBORException
if this is not the case.scan()
. -
decode
public static CBORObject decode(InputStream inputStream, boolean sequenceFlag, boolean nonDeterministic, Integer maxLength) Decodes CBOR data with options.Also see
CBORSequenceBuilder
.Decoding errors throw
CBORException
.- Parameters:
inputStream
- Stream holding CBOR datasequenceFlag
- Iftrue
stop reading after decoding a CBOR object (no object returnsnull
).nonDeterministic
- Iftrue
disable Deterministic Encoding checks for number serialization and map sorting. See alsoCBORMap.setSortingMode(boolean)
.maxLength
- Holds maximum input size in bytes ornull
(Integer.MAX_VALUE
is assumed). Since malformed CBOR objects can request arbitrary amounts of memory, it is highly recommended settingmaxLength
to a value that is adapted to the actual application.- Returns:
CBORObject
-
decode
Decodes CBOR data.This method is identical to:
decode(new ByteArrayInputStream(cborData), false, false, cborData.length);
Decoding errors throw
CBORException
.- Parameters:
cborData
- CBOR in its binary form- Returns:
CBORObject
-
equals
Checks CBOR objects for equality. -
hashCode
public int hashCode() -
toDiagnosticNotation
Returns the CBOR object in Diagnostic Notation.- Parameters:
prettyPrint
- Iftrue
white space is added to make the result easier to read. Iffalse
elements are output without additional white space (=single line).
-
toString
Returns the CBOR object in a pretty-printed form.Equivalent to
toDiagnosticNotation(boolean)
with the argument set totrue
. -
clone
Deep copy ofCBORObject
.Note that the copy is assumed to be "unread" (
checkForUnread()
).
-