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 RFC 8949 "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 CBORBigInteger
value.boolean
Get CBORboolean
.byte[]
getBytes()
Get CBORbyte string
.float
Get CBORfloating point
value.float
Get CBORfloating point
value.double
Get CBORfloating point
value.int
getInt16()
Get CBORinteger
.int
getInt32()
Get CBORinteger
.long
getInt64()
Get CBORinteger
.int
getInt8()
Get CBORinteger
.getMap()
Get CBORmap
object.Get CBORtext string
.getTag()
Get CBORtag
object.int
Get CBORinteger
.long
Get CBORinteger
.long
Get CBORinteger
.int
getUint8()
Get CBORinteger
.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 CBORBigInteger
value.This method requires that the object is a
CBORBigInt
orCBORInt
, otherwise aCBORException
is thrown.- Returns:
BigInteger
- Throws:
CBORException
-
getInt64
public long getInt64()Get CBORinteger
.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 CBORinteger
.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 CBORinteger
.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 CBORinteger
.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 CBORinteger
.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 CBORinteger
.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 CBORinteger
.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 CBORinteger
.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 CBORfloating point
value.This method requires that the object is a
CBORFloat
, otherwise aCBORException
is thrown.- Returns:
double
- Throws:
CBORException
-
getFloat32
public float getFloat32()Get CBORfloating point
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
- Throws:
CBORException
-
getFloat16
public float getFloat16()Get CBORfloating point
value.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 CBORboolean
.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 CBORtext string
.This method requires that the object is a
CBORString
, otherwise aCBORException
is thrown.- Returns:
String
- Throws:
CBORException
-
getBytes
public byte[] getBytes()Get CBORbyte string
.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()
).
-