Class CBORInt
- All Implemented Interfaces:
Cloneable,Comparable<CBORObject>
int objects.
For fine-grained control of programmatically created integers,
the following methods are provided as an alternative to the constructor:
createInt8(int),
createUint8(int),
createInt16(int),
createUint16(int),
createInt32(long),
createUint32(long), and
createInt53(long).
Note that these methods do not change data; they
only verify that data is within expected limits, and if that is the case,
finish the operation using the standard constructor.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CBORIntcreateInt16(int value) Creates a CBORint16object.static CBORIntcreateInt32(long value) Creates a CBORint32object.static CBORIntcreateInt53(long value) Creates a CBORint53object.static CBORIntcreateInt8(int value) Creates a CBORint8object.static CBORIntcreateUint16(int value) Creates a CBORuint16object.static CBORIntcreateUint32(long value) Creates a CBORuint32object.static CBORIntcreateUint8(int value) Creates a CBORuint8object.Methods inherited from class org.webpki.cbor.CBORObject
checkForUnread, clone, compareTo, encode, equals, getArray, getBigInteger, getBoolean, getBytes, getDateTime, getEpochTime, getExtendedFloat64, getFloat16, getFloat32, getFloat64, getInt128, getInt16, getInt32, getInt53, getInt64, getInt8, getMap, getSimple, getString, getTag, getUint128, getUint16, getUint32, getUint64, getUint8, hashCode, isNull, scan, toDiagnostic, toString
-
Constructor Details
-
CBORInt
public CBORInt(long value, boolean unsigned) Creates a CBOR unsigned or signedintobject.If the
unsignedflag istrue,valueis treated as an unsigned long with range0to0xffffffffffffffff.If the
unsignedflag isfalse,valueis treated as a standard java (signed) long with range-0x8000000000000000to0x7fffffffffffffff.See also
CBORBigInt(BigInteger)andCBORObject.getBigInteger().- Parameters:
value- long valueunsigned-true=> unsigned
-
CBORInt
public CBORInt(long value) Creates a CBOR signedintobject.This constructor is equivalent to
.CBORInt(value, false)- Parameters:
value- Java (signed) long
-
-
Method Details
-
createInt8
Creates a CBORint8object.This method creates a
CBORIntobject, where the value is verified to be within-0x80to0x7f.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-
createUint8
Creates a CBORuint8object.This method creates a
CBORIntobject, where the value is verified to be within0to0xff.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-
createInt16
Creates a CBORint16object.This method creates a
CBORIntobject, where the value is verified to be within-0x8000to0x7fff.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-
createUint16
Creates a CBORuint16object.This method creates a
CBORIntobject, where the value is verified to be within0to0xffff.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-
createInt32
Creates a CBORint32object.This method creates a
CBORIntobject, where the value is verified to be within-0x80000000to0x7fffffff.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-
createUint32
Creates a CBORuint32object.This method creates a
CBORIntobject, where the value is verified to be within0to0xffffffff.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-
createInt53
Creates a CBORint53object.This method creates a
CBORIntobject, where the value is verified to be within-9007199254740991to9007199254740991.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-
CBORIntdoes not support negative integers (CBOR major type 1) beyond the normal range for 64-bit signed integers (-263). In the unlikely case there is a need to explicitly deal with such integers, usingCBORBigIntis the supported workaround.