Class MessageUtils

java.lang.Object
com.dsi.ant.message.MessageUtils

public class MessageUtils extends Object
Assorted methods to assist the process of creating and parsing the payload in ANT data messages.
Since:
4.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    booleanFromByte(byte[] data, int offset)
    Converts a byte into a boolean.
    static boolean
    Parses an integer from a boolean.
    static String
    getHexString(byte[] data)
    Converts a byte array to a text string of hexadecimal numbers.
    static String
    getHexString(int number)
    Converts a number to a text string of hexadecimal numbers.
    static final boolean
    inRange(int value, int min, int max)
    Checks to see if a given value is within a set range.
    static boolean
    isFlagSet(int flagMask, byte[] data, int offset)
    Performs the same operation as isFlagSet(int, int), using a byte from a byte array as the bit set.
    static boolean
    isFlagSet(int flagMask, int flags)
    Checks if the flag(s) given in flagMask is set in the given flags.
    static int
    numberFromBits(byte[] data, int offset, int mask, int shift)
    Performs the same operations as numberFromBits(int, int, int) instead using a byte from a byte array as the bit set.
    static int
    numberFromBits(int data, int mask, int shift)
    Will return the integer value of a masked bit set in some desired magnitude range.
    static int
    numberFromBoolean(boolean data)
    Parses a boolean from an integer.
    static int
    numberFromByte(byte data)
    Parses an unsigned byte into an integer.
    static int
    numberFromByte(byte[] data, int offset)
    Parses an integer from a byte found in a byte array.
    static long
    numberFromBytes(byte[] data, int startOffset, int numberOfBytes)
    Parses an number from a set of bytes found in a byte array.
    static void
    placeInArray(boolean data, byte[] destination, int offset)
    Replaces the value in a given element of a byte array with a given boolean.
    static void
    placeInArray(int number, byte[] destination, int offset)
    Replaces the value in a given element of a byte array with a given integer.
    static void
    placeInArray(long number, byte[] destination, int numberOfBytes, int startOffset)
    Replaces the values within a byte array with a given long integer value.
    static int
    signedNumberFromByte(byte[] data, int offset)
    Parses a signed number from a byte found in a byte array.
    static long
    signedNumberFromBytes(byte[] data, int startOffset, int numberOfBytes)
    Parses a signed number from a set of bytes found in a byte array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isFlagSet

      public static boolean isFlagSet(int flagMask, int flags)
      Checks if the flag(s) given in flagMask is set in the given flags.
      Parameters:
      flagMask - The bit mask that the bit set is compared to.
      flags - The bit set that is being checked.
      Returns:
      True if any of the bits are the same between the bit mask and the bit set.
      Since:
      4.0
    • isFlagSet

      public static boolean isFlagSet(int flagMask, byte[] data, int offset)
      Performs the same operation as isFlagSet(int, int), using a byte from a byte array as the bit set.
      Parameters:
      flagMask - The bit mask that the bit set is compared to.
      data - The byte array that the desired byte will be taken from.
      offset - The byte array offset at which the byte will be taken.
      Returns:
      True if any of the bits are the same between the bit mask and the bit set.
      Since:
      4.0
    • numberFromBits

      public static int numberFromBits(byte[] data, int offset, int mask, int shift)
      Performs the same operations as numberFromBits(int, int, int) instead using a byte from a byte array as the bit set.
      Parameters:
      data - The array that holds the given value to be operated on.
      offset - The offset of the byte taken from the bit set that will be operated on.
      mask - A bit mask used to mask the bit set.
      shift - The magnitude of the right shift performed on the result of the masked bit set.
      Returns:
      The result of the operations performed on the bit set.
      Since:
      4.0
    • numberFromBits

      public static int numberFromBits(int data, int mask, int shift)
      Will return the integer value of a masked bit set in some desired magnitude range.
      Parameters:
      data - The given bit set.
      mask - A bit mask used to mask the bit set.
      shift - The magnitude of the right shift performed on the result of the masked bit set.
      Returns:
      The result of the operations performed on the bit set.
      Since:
      4.0
    • numberFromByte

      public static int numberFromByte(byte data)
      Parses an unsigned byte into an integer.
      Parameters:
      data - The given unsigned byte parameter to be parsed.
      Returns:
      The integer value of the given byte parameter.
      Since:
      4.0
    • numberFromByte

      public static int numberFromByte(byte[] data, int offset)
      Parses an integer from a byte found in a byte array.
      Parameters:
      data - The byte array from which the return byte is found.
      offset - The offset at which the desired byte is found in the byte array.
      Returns:
      The integer value of the given byte parameter.
      Since:
      4.0
    • signedNumberFromByte

      public static int signedNumberFromByte(byte[] data, int offset)
      Parses a signed number from a byte found in a byte array.
      Parameters:
      data - The byte array from which the return byte is found.
      offset - The offset at which the desired byte is found in the byte array.
      Returns:
      The signed integer value of the given byte parameter.
      Since:
      4.1
    • numberFromBytes

      public static long numberFromBytes(byte[] data, int startOffset, int numberOfBytes)
      Parses an number from a set of bytes found in a byte array.
      Parameters:
      data - The source of the byte(s) to be returned.
      startOffset - The index of the first byte of the number to be returned.
      numberOfBytes - Number of bytes the returned value will contain.
      Returns:
      The long integer value of the given byte parameter.
      Since:
      4.0
    • signedNumberFromBytes

      public static long signedNumberFromBytes(byte[] data, int startOffset, int numberOfBytes)
      Parses a signed number from a set of bytes found in a byte array.
      Parameters:
      data - The source of the byte(s) to be returned.
      startOffset - The index of the first byte of the number to be returned.
      numberOfBytes - numberOfBytes Number of bytes the returned value will contain.
      Returns:
      The signed long integer value of the given byte parameter.
      Since:
      4.1
    • booleanFromNumber

      public static boolean booleanFromNumber(int data)
      Parses an integer from a boolean.
      Parameters:
      data - The integer to be parsed.
      Returns:
      True if the integer is 1, false otherwise.
      Since:
      4.0
    • numberFromBoolean

      public static int numberFromBoolean(boolean data)
      Parses a boolean from an integer.
      Parameters:
      data - The boolean to be parsed.
      Returns:
      1 if the boolean is true, 0 otherwise.
      Since:
      4.0
    • booleanFromByte

      public static boolean booleanFromByte(byte[] data, int offset)
      Converts a byte into a boolean.
      Parameters:
      data - The byte array from which the byte of interest is taken.
      offset - The byte element of interest within the byte array.
      Returns:
      True if the byte is 1, false otherwise.
      Since:
      4.0
    • placeInArray

      public static void placeInArray(boolean data, byte[] destination, int offset)
      Replaces the value in a given element of a byte array with a given boolean.
      Parameters:
      data - The boolean that will replace the desired element's current value.
      destination - The byte array that will be altered.
      offset - The index of the element that will be altered.
      Since:
      4.0
    • placeInArray

      public static void placeInArray(int number, byte[] destination, int offset)
      Replaces the value in a given element of a byte array with a given integer.
      Parameters:
      number - The integer that will replace the desired element's current value.
      destination - The byte array that will be altered.
      offset - The index of the element that will be altered.
      Since:
      4.0
    • placeInArray

      public static void placeInArray(long number, byte[] destination, int numberOfBytes, int startOffset)
      Replaces the values within a byte array with a given long integer value.
      Parameters:
      number - The value that will replace the desired element's current value.
      destination - The byte array that will be altered.
      numberOfBytes - The number of bytes that will be replaced in the array.
      startOffset - The first element that will be replaced in destination
      Since:
      4.0
    • inRange

      public static final boolean inRange(int value, int min, int max)
      Checks to see if a given value is within a set range.
      Parameters:
      value - The value to be checked against the given bounds.
      min - The minimum bound of the set range.
      max - The maximum bound of the set range.
      Returns:
      Returns true if the value is in the range, false otherwise.
      Since:
      4.0
    • getHexString

      public static String getHexString(int number)
      Converts a number to a text string of hexadecimal numbers.
      Parameters:
      number - The integer to be converted into the hexadecimal number string.
      Returns:
      A String of the form 0x##
      Since:
      4.0
    • getHexString

      public static String getHexString(byte[] data)
      Converts a byte array to a text string of hexadecimal numbers.
      Parameters:
      data - The byte array to be converted into the hexadecimal number string.
      Returns:
      A text string of the form [0x##][0x##]...
      Since:
      4.0