org.npsnet.xrti.utilities
Class EncodingHelpers

java.lang.Object
  extended byorg.npsnet.xrti.utilities.EncodingHelpers

public class EncodingHelpers
extends java.lang.Object

Utility methods for encoding and decoding basic types, modeled after those supplied with the DMSO RTI.

Author:
Andrzej Kapolka

Constructor Summary
EncodingHelpers()
           
 
Method Summary
static boolean decodeBoolean(byte[] buffer)
          Decodes and returns the value stored in the specified buffer.
static byte decodeByte(byte[] buffer)
          Decodes and returns the value stored in the specified buffer.
static double decodeDouble(byte[] buffer)
          Decodes and returns the value stored in the specified buffer.
static float decodeFloat(byte[] buffer)
          Decodes and returns the value stored in the specified buffer.
static char decodeChar(byte[] buffer)
          Decodes and returns the value stored in the specified buffer.
static int decodeInt(byte[] buffer)
          Decodes and returns the value stored in the specified buffer.
static long decodeLong(byte[] buffer)
          Decodes and returns the value stored in the specified buffer.
static short decodeShort(byte[] buffer)
          Decodes and returns the value stored in the specified buffer.
static java.lang.String decodeString(byte[] buffer)
          Decodes and returns the value stored in the specified buffer.
static byte[] encodeBoolean(boolean value)
          Encodes the specified value, returning the result as a byte array.
static byte[] encodeByte(byte value)
          Encodes the specified value, returning the result as a byte array.
static byte[] encodeDouble(double value)
          Encodes the specified value, returning the result as a byte array.
static byte[] encodeFloat(float value)
          Encodes the specified value, returning the result as a byte array.
static byte[] encodeChar(char value)
          Encodes the specified value, returning the result as a byte array.
static byte[] encodeInt(int value)
          Encodes the specified value, returning the result as a byte array.
static byte[] encodeLong(long value)
          Encodes the specified value, returning the result as a byte array.
static byte[] encodeShort(short value)
          Encodes the specified value, returning the result as a byte array.
static byte[] encodeString(java.lang.String value)
          Encodes the specified value, returning the result as a byte array.
static void reverse(byte[] buffer)
          Reverses the specified byte array in-place.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncodingHelpers

public EncodingHelpers()
Method Detail

encodeBoolean

public static byte[] encodeBoolean(boolean value)
Encodes the specified value, returning the result as a byte array.

Parameters:
value - the value to encode
Returns:
a byte array containing the encoded value

encodeByte

public static byte[] encodeByte(byte value)
Encodes the specified value, returning the result as a byte array.

Parameters:
value - the value to encode
Returns:
a byte array containing the encoded value

encodeChar

public static byte[] encodeChar(char value)
Encodes the specified value, returning the result as a byte array.

Parameters:
value - the value to encode
Returns:
a byte array containing the encoded value

encodeDouble

public static byte[] encodeDouble(double value)
Encodes the specified value, returning the result as a byte array.

Parameters:
value - the value to encode
Returns:
a byte array containing the encoded value

encodeFloat

public static byte[] encodeFloat(float value)
Encodes the specified value, returning the result as a byte array.

Parameters:
value - the value to encode
Returns:
a byte array containing the encoded value

encodeInt

public static byte[] encodeInt(int value)
Encodes the specified value, returning the result as a byte array.

Parameters:
value - the value to encode
Returns:
a byte array containing the encoded value

encodeLong

public static byte[] encodeLong(long value)
Encodes the specified value, returning the result as a byte array.

Parameters:
value - the value to encode
Returns:
a byte array containing the encoded value

encodeShort

public static byte[] encodeShort(short value)
Encodes the specified value, returning the result as a byte array.

Parameters:
value - the value to encode
Returns:
a byte array containing the encoded value

encodeString

public static byte[] encodeString(java.lang.String value)
Encodes the specified value, returning the result as a byte array.

Parameters:
value - the value to encode
Returns:
a byte array containing the encoded value

decodeBoolean

public static boolean decodeBoolean(byte[] buffer)
                             throws CouldNotDecode
Decodes and returns the value stored in the specified buffer.

Parameters:
buffer - the buffer containing the encoded value
Returns:
the decoded value
Throws:
CouldNotDecode - if the value could not be decoded

decodeByte

public static byte decodeByte(byte[] buffer)
                       throws CouldNotDecode
Decodes and returns the value stored in the specified buffer.

Parameters:
buffer - the buffer containing the encoded value
Returns:
the decoded value
Throws:
CouldNotDecode - if the value could not be decoded

decodeChar

public static char decodeChar(byte[] buffer)
                       throws CouldNotDecode
Decodes and returns the value stored in the specified buffer.

Parameters:
buffer - the buffer containing the encoded value
Returns:
the decoded value
Throws:
CouldNotDecode - if the value could not be decoded

decodeDouble

public static double decodeDouble(byte[] buffer)
                           throws CouldNotDecode
Decodes and returns the value stored in the specified buffer.

Parameters:
buffer - the buffer containing the encoded value
Returns:
the decoded value
Throws:
CouldNotDecode - if the value could not be decoded

decodeFloat

public static float decodeFloat(byte[] buffer)
                         throws CouldNotDecode
Decodes and returns the value stored in the specified buffer.

Parameters:
buffer - the buffer containing the encoded value
Returns:
the decoded value
Throws:
CouldNotDecode - if the value could not be decoded

decodeInt

public static int decodeInt(byte[] buffer)
                     throws CouldNotDecode
Decodes and returns the value stored in the specified buffer.

Parameters:
buffer - the buffer containing the encoded value
Returns:
the decoded value
Throws:
CouldNotDecode - if the value could not be decoded

decodeLong

public static long decodeLong(byte[] buffer)
                       throws CouldNotDecode
Decodes and returns the value stored in the specified buffer.

Parameters:
buffer - the buffer containing the encoded value
Returns:
the decoded value
Throws:
CouldNotDecode - if the value could not be decoded

decodeShort

public static short decodeShort(byte[] buffer)
                         throws CouldNotDecode
Decodes and returns the value stored in the specified buffer.

Parameters:
buffer - the buffer containing the encoded value
Returns:
the decoded value
Throws:
CouldNotDecode - if the value could not be decoded

decodeString

public static java.lang.String decodeString(byte[] buffer)
                                     throws CouldNotDecode
Decodes and returns the value stored in the specified buffer.

Parameters:
buffer - the buffer containing the encoded value
Returns:
the decoded value
Throws:
CouldNotDecode - if the value could not be decoded

reverse

public static void reverse(byte[] buffer)
Reverses the specified byte array in-place.

Parameters:
buffer - the byte array to reverse