Class CBORInt

All Implemented Interfaces:
Cloneable

public class CBORInt extends 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.

Applications that are intended to work with multiple platforms should for interoperability reasons not exploit CBOR 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)
to 2
n
-1
, where n 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 to 0x7fffffff. Note that range constraints do not apply to CBOR integer numbers that are shorter than the actual target integer type. Also see CBORObject.getInt().
  • Constructor Details

    • CBORInt

      public CBORInt(long value, boolean unsigned)
      Creates a CBOR unsigned or negative integer.

      To cope with the entire 65-bit integer span supported by CBOR, this constructor must be used. Unsigned integers range from 0 to 2
      64
      -1
      , while negative integers range from -1 to -2
      64
      .

      If the unsigned flag is set to false, 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 by 1. This means that the input values 0, 9223372036854775807L, -9223372036854775808L, and -1, actually represent -1, -9223372036854775808, -9223372036854775809, and -18446744073709551616 (-2
      64
      ) respectively.

      Also see Range Constraints and CBORBigInt(BigInteger).

      Parameters:
      value - long value
      unsigned - true if value should be considered as unsigned
    • CBORInt

      public CBORInt(long value)
      Creates a CBOR signed integer value.

      Also see CBORInt(long,boolean) and CBORBigInt(BigInteger).

      Parameters:
      value - Java (signed) long type