Class CBORInt

All Implemented Interfaces:
Cloneable, Comparable<CBORObject>

public class CBORInt extends CBORObject
Class for holding CBOR integer 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), 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 Details

    • CBORInt

      public CBORInt(BigInteger value)
      Creates a CBOR integer object.

      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 CBOR int object.

      If the unsigned flag is true, value is treated as an unsigned long with range 0 to 0xffffffffffffffff.

      If the unsigned flag is false, value is treated as a standard java (signed) long with range -0x8000000000000000 to 0x7fffffffffffffff.

      Parameters:
      value - long value
      unsigned - true => unsigned
      See Also:
    • CBORInt

      public CBORInt(long value)
      Creates a CBOR signed int object.

      This constructor is equivalent to CBORInt(value, false).

      Parameters:
      value - Java (signed) long
  • Method Details

    • createInt8

      public static CBORInt createInt8(int value)
      Creates a CBOR int8 object.

      This method creates a CBORInt object, where the value is verified to be within -0x80 to 0x7f.

      Parameters:
      value - Integer
      Returns:
      CBORInt object
      Throws:
      CBORException - If value is out of range
      See Also:
    • createUint8

      public static CBORInt createUint8(int value)
      Creates a CBOR uint8 object.

      This method creates a CBORInt object, where the value is verified to be within 0 to 0xff.

      Parameters:
      value - Integer
      Returns:
      CBORInt object
      Throws:
      CBORException - If value is out of range
      See Also:
    • createInt16

      public static CBORInt createInt16(int value)
      Creates a CBOR int16 object.

      This method creates a CBORInt object, where the value is verified to be within -0x8000 to 0x7fff.

      Parameters:
      value - Integer
      Returns:
      CBORInt object
      Throws:
      CBORException - If value is out of range
      See Also:
    • createUint16

      public static CBORInt createUint16(int value)
      Creates a CBOR uint16 object.

      This method creates a CBORInt object, where the value is verified to be within 0 to 0xffff.

      Parameters:
      value - Integer
      Returns:
      CBORInt object
      Throws:
      CBORException - If value is out of range
      See Also:
    • createInt32

      public static CBORInt createInt32(long value)
      Creates a CBOR int32 object.

      This method creates a CBORInt object, where the value is verified to be within -0x80000000 to 0x7fffffff.

      Parameters:
      value - Integer
      Returns:
      CBORInt object
      Throws:
      CBORException - If value is out of range
      See Also:
    • createUint32

      public static CBORInt createUint32(long value)
      Creates a CBOR uint32 object.

      This method creates a CBORInt object, where the value is verified to be within 0 to 0xffffffff.

      Parameters:
      value - Integer
      Returns:
      CBORInt object
      Throws:
      CBORException - If value is out of range
      See Also:
    • createInt53

      public static CBORInt createInt53(long value)
      Creates a CBOR int53 object.

      This method creates a CBORInt object, where the value is verified to be within the JavaScript limits Number.MIN_SAFE_INTEGER (-9007199254740991) to Number.MAX_SAFE_INTEGER (9007199254740991).

      Since 53-bit integers are specific to JavaScript, int53 objects should be used with caution in cross-platform scenarios.

      Parameters:
      value - Integer
      Returns:
      CBORInt object
      Throws:
      CBORException - If value is out of range
      See Also:
    • createInt128

      public static CBORInt createInt128(BigInteger value)
      Creates a CBOR int128 object.

      This method creates a CBORInt object, where the value is verified to be within -0x80000000000000000000000000000000 to 0x7fffffffffffffffffffffffffffffff.

      Parameters:
      value - Integer
      Returns:
      CBORInt object
      Throws:
      CBORException - If value is out of range
      See Also:
    • createUint128

      public static CBORInt createUint128(BigInteger value)
      Creates a CBOR uint128 object.

      This method creates a CBORInt object, where the value is verified to be within 0 to 0xffffffffffffffffffffffffffffffff.

      Parameters:
      value - Integer
      Returns:
      CBORInt object
      Throws:
      CBORException - If value is out of range
      See Also: