Class CBORObject
- All Implemented Interfaces:
Cloneable
,Comparable<CBORObject>
- Direct Known Subclasses:
CBORArray
,CBORBigInt
,CBORBoolean
,CBORBytes
,CBORFloat
,CBORInt
,CBORMap
,CBORNull
,CBORString
,CBORTag
In this implementation "object" should be regarded as equivalent to the CBOR [RFC 8949] term, "data item".
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Check CBOR object for unread data.clone()
Create deep copy of CBOR object.int
compareTo
(CBORObject object) Compare CBOR objects for magnitude.byte[]
encode()
Encode CBOR object.boolean
Compare CBOR objects for equality.getArray()
Get CBORarray
object.Get CBORbigint
object.boolean
Get CBORbool
object.byte[]
getBytes()
Get CBORbstr
object.Get ISOdate/time
object.Get UNIXEpoch
time object.float
Get CBORfloat16
object.float
Get CBORfloat32
object.double
Get CBORfloat64
object.int
getInt16()
Get CBORint
object.int
getInt32()
Get CBORint
object.long
getInt64()
Get CBORint
object.int
getInt8()
Get CBORint
object.getMap()
Get CBORmap
object.Get CBORtstr
object.getTag()
Get CBORtag
object.int
Get CBORuint
object.long
Get CBORuint
object.long
Get CBORuint
object.int
getUint8()
Get CBORuint
object.int
hashCode()
Calculate hash code of CBOR object.boolean
isNull()
Check for CBORnull
.scan()
Scan CBOR object and mark it as read.toDiagnosticNotation
(boolean prettyPrint) Render CBOR object in Diagnostic Notation.toString()
Render CBOR object in a pretty-printed form.
-
Method Details
-
encode
public byte[] encode()Encode CBOR object.Note: this method always return CBOR data using Deterministic Encoding.
- Returns:
- CBOR encoded
byteArray
-
getBigInteger
Get CBORbigint
object.This method requires that the object is a
CBORBigInt
orCBORInt
, otherwise aCBORException
is thrown.- Returns:
BigInteger
- Throws:
CBORException
-
getInt64
public long getInt64()Get CBORint
object.This method requires that the object is a
CBORInt
and has a value ranging from-0x8000000000000000
to0x7fffffffffffffff
.- Returns:
long
- Throws:
CBORException
-
getUint64
public long getUint64()Get CBORuint
object.This method requires that the object is a
CBORInt
and has a value ranging from0
to0xffffffffffffffff
.- Returns:
long
- Throws:
CBORException
-
getInt32
public int getInt32()Get CBORint
object.This method requires that the object is a
CBORInt
and has a value ranging from-0x80000000
to0x7fffffff
.- Returns:
int
- Throws:
CBORException
-
getUint32
public long getUint32()Get CBORuint
object.This method requires that the object is a
CBORInt
and has a value ranging from0
to0xffffffff
.- Returns:
long
- Throws:
CBORException
-
getInt16
public int getInt16()Get CBORint
object.This method requires that the object is a
CBORInt
and has a value ranging from-0x8000
to0x7fff
.- Returns:
int
- Throws:
CBORException
-
getUint16
public int getUint16()Get CBORuint
object.This method requires that the object is a
CBORInt
and has a value ranging from0
to0xffff
.- Returns:
int
- Throws:
CBORException
-
getInt8
public int getInt8()Get CBORint
object.This method requires that the object is a
CBORInt
and has a value ranging from-0x80
to0x7f
.- Returns:
int
- Throws:
CBORException
-
getUint8
public int getUint8()Get CBORuint
object.This method requires that the object is a
CBORInt
and has a value ranging from0
to0xff
.- Returns:
int
- Throws:
CBORException
-
getFloat64
public double getFloat64()Get CBORfloat64
object.This method requires that the object is a
CBORFloat
, otherwise aCBORException
is thrown.- Returns:
double
- Throws:
CBORException
-
getFloat32
public float getFloat32()Get CBORfloat32
object.This method requires that the object is a
CBORFloat
holding a 16 or 32-bit IEEE 754 value, otherwise aCBORException
is thrown.- Returns:
float
- Throws:
CBORException
-
getFloat16
public float getFloat16()Get CBORfloat16
object.This method requires that the object is a
CBORFloat
holding a 16-bit IEEE 754 value, otherwise aCBORException
is thrown.- Returns:
float
- Throws:
CBORException
-
getBoolean
public boolean getBoolean()Get CBORbool
object.This method requires that the object is a
CBORBoolean
, otherwise aCBORException
is thrown.- Returns:
boolean
- Throws:
CBORException
-
isNull
public boolean isNull()Check for CBORnull
.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
Get CBORtstr
object.This method requires that the object is a
CBORString
, otherwise aCBORException
is thrown.- Returns:
String
- Throws:
CBORException
-
getEpochTime
Get UNIXEpoch
time object.This method requires that the underlying object is a
CBORInt
orCBORFloat
, otherwise aCBORException
is thrown.- Returns:
GregorianCalendar
- Throws:
CBORException
- See Also:
-
getDateTime
Get ISOdate/time
object.This method requires that the underlying object is a
CBORString
that is compatible with ISO date/time [RFC 3339], otherwise aCBORException
is thrown.- Returns:
GregorianCalendar
- Throws:
CBORException
IllegalArgumentException
- See Also:
-
getBytes
public byte[] getBytes()Get CBORbstr
object.This method requires that the object is a
CBORBytes
, otherwise aCBORException
is thrown.- Returns:
byteArray
- Throws:
CBORException
-
getMap
Get CBORmap
object.This method requires that the object is a
CBORMap
, otherwise aCBORException
is thrown.- Returns:
- CBOR
map
object - Throws:
CBORException
-
getArray
Get CBORarray
object.This method requires that the object is a
CBORArray
, otherwise aCBORException
is thrown.- Returns:
- CBOR
array
object - Throws:
CBORException
-
getTag
Get CBORtag
object.This method requires that the object is a
CBORTag
, otherwise aCBORException
is thrown.- Returns:
- CBOR
tag
object - Throws:
CBORException
-
scan
Scan CBOR object and mark it as read.This method sets the status of this object as well as to possible child objects to "read".
See alsocheckForUnread()
.- Returns:
this
-
checkForUnread
public void checkForUnread()Check CBOR object for unread data.Verifies that all objects from the current object including possible child objects have been read (through calling
See alsogetBytes()
etc.), and throws aCBORException
if this is not the case.scan()
.- Throws:
CBORException
-
equals
Compare CBOR objects for equality. -
compareTo
Compare CBOR objects for magnitude.- Specified by:
compareTo
in interfaceComparable<CBORObject>
-
hashCode
public int hashCode()Calculate hash code of CBOR object. -
toDiagnosticNotation
Render 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
Render CBOR object in a pretty-printed form.Equivalent to
toDiagnosticNotation(boolean)
with the argument set totrue
. -
clone
Create deep copy of CBOR object.Note that the copy is assumed to be "unread" (
checkForUnread()
).
-