Class CBORNonFinite

java.lang.Object
org.webpki.cbor.CBORObject
org.webpki.cbor.CBORNonFinite
All Implemented Interfaces:
Cloneable, Comparable<CBORObject>

public class CBORNonFinite extends CBORObject
Class for holding CBOR non-finite float objects.

See also CBORFloat.

  • Constructor Details

    • CBORNonFinite

      public CBORNonFinite(long value)
      Creates a CBOR non-finite float object.

      The constructor takes a 16, 32, or 64-bit non-finite number in IEEE-754 encoding.

      See also CBORFloat(double) and CBORFloat.createExtendedFloat(double).

      Parameters:
      value - long holding the number
      Throws:
      CBORException - If the argument is not within the non-finite number space
  • Method Details

    • createPayloadObject

      public static CBORNonFinite createPayloadObject(long payload)
      Creates a payload object.
      Traditionally, the non-finite number space is used for propagating math-related problems such as division by zero.
      However, in some cases there may be a desire providing more application specific data, like debug information related to faulty sensors. The createPayloadObject(long) and getPayloadData() methods were designed for this particular purpose. To obviate the need defining another CBOR type, these methods are "piggybacking" on the existing non-finite number space. The following table represents these methods from a developer perspective:
      Payload
      d51-d0 in big-endian order
      The payload bits are conceptually put into an IEEE-754 64-bit object having the following layout:
      SignExponentSignificand
      011111111111d0-d51 in little-endian order
      The reason for reversing the payload bits is to ensure that a specific bit will remain in a fix position (maintain the same value), independent of the size of the IEEE-754 variant used for encoding. For setting the sign bit, see setSign(boolean).
      Note that the encoder will (due to CBOR deterministic encoding rules), select the shortest serialization required to properly represent the payload. The following table shows a few examples:
      Payload (hex)CBOR EncodingDiagnostic Notation
      0f97c00Infinity
      1f97e00NaN
      2f97d00float'7d00'
      3fff97ffffloat'7fff'
      400fa7f801000float'7f801000'
      7ffffffa7ffffffffloat'7fffffff'
      800000fb7ff0000010000000float'7ff0000010000000'
      ffffffffffffffb7ffffffffffffffffloat'7fffffffffffffff'
      CBORNonFinite(long) represents another way creating a non-finite float.
      Parameters:
      payload - Payload
      Returns:
      CBORNonFinite. Also see CBOR wrapper objects.
      See Also:
    • getPayloadData

      public long getPayloadData()
      Get payload data.

      This method is the "consumer" counterpart to createPayloadObject(long).

      Returns:
      Payload
    • setSign

      public CBORNonFinite setSign(boolean on)
      Set the sign bit of the non-finite float.
      Parameters:
      on - Sign bit
      Returns:
      CBORNonFinite
      See Also:
    • getSign

      public boolean getSign()
      Get the sign bit of the non-finite float.
      Returns:
      Sign bit expressed as a boolean
      See Also:
    • length

      public int length()
      Get length of CBOR non-finite object.

      Note that you must cast a CBORObject to CBORNonFinite in order to access length().

      Returns:
      Length in bytes: 2, 4, or 8.
    • isSimple

      public boolean isSimple()
      Check if CBOR non-finite object is simple.

      This method returns true if the non-finite object is a "quiet" NaN, Infinity, or -Infinity, else it returns false.

      Returns:
      boolean.
    • isNaN

      public boolean isNaN()
      Check if CBOR non-finite object is a NaN.

      This method returns true for all conformant NaN variants, else it returns false.

      Returns:
      boolean.
    • getNonFinite

      public long getNonFinite()
      Get actual CBOR non-finite float object.

      This method returns the value of a CBOR non-finite object. The value is provided in the most compact form based on CBOR serialization rules.

      Returns:
      IEEE-754 non-finite number coded as a long
    • getNonFinite64

      public long getNonFinite64()
      Get expanded CBOR non-finite float object.

      This method returns the value of a CBOR non-finite object after it has been expanded to 64 bits. That is, a received 7c01 will be returned as 7ff0040000000000.

      Returns:
      IEEE-754 non-finite number coded as a long