Class SerializerUtils

java.lang.Object
net.mtrop.doom.struct.io.SerializerUtils

public final class SerializerUtils extends Object
Contains utility methods for serializing values.
Author:
Matthew Tropiano
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
     
    static final boolean
     
    static final int
    The size of a byte in bytes (This should always be 1, or Sun screwed up).
    static final int
    The size of an int in bytes.
    static final int
    The size of a long in bytes.
    static final int
    The size of a short in bytes.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    booleansToInt(boolean... bool)
    Converts a series of boolean values to bits, going from least-significant to most-significant.
    static double
    bytesToDouble(byte[] b, int offset, boolean endianMode)
    Converts a series of bytes to a 64-bit float.
    static float
    bytesToFloat(byte[] b, int offset, boolean endianMode)
    Converts a series of bytes to a 32-bit float.
    static int
    bytesToInt(byte[] b, int offset, boolean endianMode)
    Converts a series of bytes to an integer.
    static long
    bytesToLong(byte[] b, int offset, boolean endianMode)
    Converts a series of bytes to a long.
    static short
    bytesToShort(byte[] b, int offset, boolean endianMode)
    Converts a series of bytes to a short.
    static int
    doubleToBytes(double d, boolean endianMode, byte[] out, int offset)
    Converts a double to a series of bytes.
    static int
    floatToBytes(float f, boolean endianMode, byte[] out, int offset)
    Converts a float to a series of bytes.
    static int
    intToBytes(int i, boolean endianMode, byte[] out, int offset)
    Converts an integer to a series of bytes.
    static int
    longToBytes(long l, boolean endianMode, byte[] out, int offset)
    Converts a long to a series of bytes.
    static int
    shortToBytes(short s, boolean endianMode, byte[] out, int offset)
    Converts a short to a series of bytes.

    Methods inherited from class java.lang.Object

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

    • SIZEOF_INT

      public static final int SIZEOF_INT
      The size of an int in bytes.
      See Also:
    • SIZEOF_BYTE

      public static final int SIZEOF_BYTE
      The size of a byte in bytes (This should always be 1, or Sun screwed up).
      See Also:
    • SIZEOF_SHORT

      public static final int SIZEOF_SHORT
      The size of a short in bytes.
      See Also:
    • SIZEOF_LONG

      public static final int SIZEOF_LONG
      The size of a long in bytes.
      See Also:
    • LITTLE_ENDIAN

      public static final boolean LITTLE_ENDIAN
      See Also:
    • BIG_ENDIAN

      public static final boolean BIG_ENDIAN
      See Also:
  • Method Details

    • bytesToShort

      public static short bytesToShort(byte[] b, int offset, boolean endianMode)
      Converts a series of bytes to a short.
      Parameters:
      b - the bytes to convert.
      offset - the offset into the byte array.
      endianMode - the endian mode of the bytes.
      Returns:
      the resultant value.
    • bytesToInt

      public static int bytesToInt(byte[] b, int offset, boolean endianMode)
      Converts a series of bytes to an integer.
      Parameters:
      b - the bytes to convert.
      offset - the offset into the byte array.
      endianMode - the endian mode of the bytes.
      Returns:
      the resultant value.
    • bytesToLong

      public static long bytesToLong(byte[] b, int offset, boolean endianMode)
      Converts a series of bytes to a long.
      Parameters:
      b - the bytes to convert.
      offset - the offset into the byte array.
      endianMode - the endian mode of the bytes.
      Returns:
      the resultant value.
    • bytesToFloat

      public static float bytesToFloat(byte[] b, int offset, boolean endianMode)
      Converts a series of bytes to a 32-bit float.
      Parameters:
      b - the bytes to convert.
      offset - the offset into the byte array.
      endianMode - the endian mode of the bytes.
      Returns:
      the resultant value.
    • bytesToDouble

      public static double bytesToDouble(byte[] b, int offset, boolean endianMode)
      Converts a series of bytes to a 64-bit float.
      Parameters:
      b - the bytes to convert.
      offset - the offset into the byte array.
      endianMode - the endian mode of the bytes.
      Returns:
      the resultant value.
    • shortToBytes

      public static int shortToBytes(short s, boolean endianMode, byte[] out, int offset)
      Converts a short to a series of bytes.
      Parameters:
      s - the short to convert.
      endianMode - the endian mode of the bytes.
      out - the output array.
      offset - the offset into the array to write.
      Returns:
      the next array offset after the write.
    • intToBytes

      public static int intToBytes(int i, boolean endianMode, byte[] out, int offset)
      Converts an integer to a series of bytes.
      Parameters:
      i - the integer to convert.
      endianMode - the endian mode of the bytes.
      out - the output array.
      offset - the offset into the array to write.
      Returns:
      the next array offset after the write.
    • longToBytes

      public static int longToBytes(long l, boolean endianMode, byte[] out, int offset)
      Converts a long to a series of bytes.
      Parameters:
      l - the long to convert.
      endianMode - the endian mode of the bytes.
      out - the output array.
      offset - the offset into the array to write.
      Returns:
      the next array offset after the write.
    • floatToBytes

      public static int floatToBytes(float f, boolean endianMode, byte[] out, int offset)
      Converts a float to a series of bytes.
      Parameters:
      f - the float to convert.
      endianMode - the endian mode of the bytes.
      out - the output array.
      offset - the offset into the array to write.
      Returns:
      the next array offset after the write.
    • doubleToBytes

      public static int doubleToBytes(double d, boolean endianMode, byte[] out, int offset)
      Converts a double to a series of bytes.
      Parameters:
      d - the double to convert.
      endianMode - the endian mode of the bytes.
      out - the output array.
      offset - the offset into the array to write.
      Returns:
      the next array offset after the write.
    • booleansToInt

      public static int booleansToInt(boolean... bool)
      Converts a series of boolean values to bits, going from least-significant to most-significant. TRUE booleans set the bit, FALSE ones do not.
      Parameters:
      bool - list of booleans. cannot exceed 32.
      Returns:
      the resultant bitstring in an integer.