Class CBORInt

All Implemented Interfaces:
Cloneable, Comparable<CBORObject>

public class CBORInt extends CBORObject
Class for holding CBOR int objects.
Note that CBORInt does 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, using CBORBigInt is the supported workaround.

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 Details

    • CBORInt

      public CBORInt(long value, boolean unsigned)
      Creates a CBOR unsigned or signed 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.

      See also CBORBigInt(BigInteger) and CBORObject.getBigInteger().

      Parameters:
      value - long value
      unsigned - true => unsigned
    • 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 -9007199254740991 to 9007199254740991.

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