Package org.webpki.cbor
Class CBORInt
java.lang.Object
org.webpki.cbor.CBORObject
org.webpki.cbor.CBORInt
- All Implemented Interfaces:
Cloneable
,Comparable<CBORObject>
Class for holding CBOR
integer
objects.
Note that the encoder is adaptive, selecting the shortest possible representation in order to produce a fully deterministic result.
-
Constructor Summary
-
Method Summary
Methods inherited from class org.webpki.cbor.CBORObject
checkForUnread, clone, compareTo, encode, equals, getArray, getBigInteger, getBoolean, getBytes, getFloat16, getFloat32, getFloat64, getInt16, getInt32, getInt64, getInt8, getMap, getString, getTag, getUint16, getUint32, getUint64, getUint8, hashCode, isNull, scan, toDiagnosticNotation, toString
-
Constructor Details
-
CBORInt
public CBORInt(long value, boolean unsigned) Creates a CBOR unsigned or negativeinteger
.0
to264-1
, while negative integers range from-1
to-264
.unsigned
flag is set tofalse
, this constructor assumes CBOR native encoding mode for negative integers. That is,value
is treated as an unsigned magnitude which is subsequently negated and subtracted by1
. This means that the input values0
,9223372036854775807L
,-9223372036854775808L
, and-1
, actually represent-1
,-9223372036854775808
,-9223372036854775809
, and-18446744073709551616
(-264
) respectively.See also Range Constraints and
CBORBigInt(BigInteger)
.- Parameters:
value
- long valueunsigned
-true
if value should be considered as unsigned
-
CBORInt
public CBORInt(long value) Creates a CBOR signedinteger
.See also
CBORInt(long,boolean)
andCBORBigInt(BigInteger)
.- Parameters:
value
- Java (signed) long type
-
integer
numbers outside of the traditional range for"unsigned"
and"signed"
integers. Translated to values, the recommended range would then span from-2(n-1)
to2n-1
, wheren
is the size in bits of the anticipated target integer type. That is, if a protocol schema or declaration calls for a signed 32-bit integer, the valid range would be-0x80000000
to0x7fffffff
. See alsoCBORObject.getInt32()
.