Class CBORInt
- All Implemented Interfaces:
Cloneable,Comparable<CBORObject>
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),
createInt53(long),
createInt128(BigInteger), and
createUint128(BigInteger).
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 one of the standard constructors.
-
Constructor Summary
ConstructorsConstructorDescriptionCBORInt(long value) Creates a CBOR signedintobject.CBORInt(long value, boolean unsigned) Creates a CBORintobject.CBORInt(BigInteger value) Creates a CBORintegerobject. -
Method Summary
Modifier and TypeMethodDescriptionstatic CBORIntcreateInt128(BigInteger value) Creates a CBORint128object.static 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 CBORIntcreateUint128(BigInteger value) Creates a CBORuint128object.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, 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
Creates a CBORintegerobject.Constructor supporting integers of any size.
Note that using this constructor or one of the other constrctors do not affect CBOR encoding; it is only about accommodating integers of different size.
- Parameters:
value- Big integer value- See Also:
-
CBORInt
public CBORInt(long value, boolean unsigned) Creates a CBORintobject.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.- Parameters:
value- long valueunsigned-true=> unsigned- See Also:
-
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 the JavaScript limitsNumber.MIN_SAFE_INTEGER(-9007199254740991) toNumber.MAX_SAFE_INTEGER(9007199254740991).Since 53-bit integers are specific to JavaScript,
int53objects should be used with caution in cross-platform scenarios.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-
createInt128
Creates a CBORint128object.This method creates a
CBORIntobject, where the value is verified to be within-0x80000000000000000000000000000000to0x7fffffffffffffffffffffffffffffff.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-
createUint128
Creates a CBORuint128object.This method creates a
CBORIntobject, where the value is verified to be within0to0xffffffffffffffffffffffffffffffff.- Parameters:
value- Integer- Returns:
CBORIntobject- Throws:
CBORException- If value is out of range- See Also:
-