copyright The Portico Project 2008.

org.portico.shared.compat
Class JEncodingHelpers

java.lang.Object
  extended by org.portico.shared.compat.JEncodingHelpers

public class JEncodingHelpers
extends Object

A set of encoding helpers (based on the HLA 1.3 encoding helpers) that can be used safely without referring to any specific HLA version.


Constructor Summary
JEncodingHelpers()
           
 
Method Summary
static boolean decodeBoolean(byte[] buffer)
          Decodes a big-endian 32-bit integer in a buffer into a boolean.
static boolean decodeBoolean(byte[] buffer, int offset)
          Decodes a big-endian 32-bit integer in a 4-byte buffer at the specified offset int a boolean value.
static byte decodeByte(byte[] buffer)
          Decodes a byte from a buffer.
static byte decodeByte(byte[] buffer, int offset)
          Decodes a byte from a buffer at the specified offset.
static char decodeChar(byte[] buffer)
          Decodes a big-endian 16-bit integer in a buffer into a char value.
static char decodeChar(byte[] buffer, int offset)
          Decodes a big-endian 16-bit integer in a buffer at the specified offset into a char value.
static double decodeDouble(byte[] buffer)
          Decodes a big-endian 64-bit integer stored in buffer into a long value and converts that to a double value, which is returned.
static double decodeDouble(byte[] buffer, int offset)
          Decodes a big-endian 64-bit integer stored in buffer at specified offset into a long value and converts that to a double value, which is returned.
static float decodeFloat(byte[] buffer)
          Decodes a big-endian 32-bit integer stored in buffer into an int value and converts that to a float value, which is returned.
static float decodeFloat(byte[] buffer, int offset)
          Decodes a big-endian 32-bit integer stored in buffer at specified offset into an int value and converts that to a float value, which is returned.
static int decodeInt(byte[] buffer)
          Decodes a big-endian 32-bit integer stored in buffer into an int value.
static int decodeInt(byte[] buffer, int offset)
          Decodes a big-endian 32-bit integer stored in buffer at specified offset into an int value.
static long decodeLong(byte[] buffer)
          Decodes a big-endian 64-bit integer stored in buffer into a long value.
static long decodeLong(byte[] buffer, int offset)
          Decodes a big-endian 64-bit integer stored in buffer at specified offset into a long value.
static short decodeShort(byte[] buffer)
          Decodes a big-endian 16-bit integer stored in buffer into a short value.
static short decodeShort(byte[] buffer, int offset)
          Decodes a big-endian 16-bit integer stored in buffer at specified offset into a short value.
static String decodeString(byte[] buffer)
          Decodes a string from a buffer and strips the final null character.
static byte[] encodeBoolean(boolean value)
          Encodes a boolean value as a big-endian 32-bit integer in a 4-byte buffer and returns the buffer.
static void encodeBoolean(boolean value, byte[] buffer, int offset)
          Encodes a boolean value as a big-endian 32-bit integer into the specified buffer at the specified offset.
static byte[] encodeByte(int value)
          Encodes a byte in a buffer and returns the buffer.
static void encodeByte(int value, byte[] buffer, int offset)
          Encodes a byte into a buffer at the specified offset.
static byte[] encodeChar(char value)
          Encodes a char value as a big-endian 16-bit integer into a 2-byte buffer and returns the buffer.
static void encodeChar(char value, byte[] buffer, int offset)
          Encodes a char value as a big-endian 16-bit integer into a buffer at the specified offset.
static byte[] encodeDouble(double value)
          Converts a double value to a long and stores that long value as a big-endian 64-bit integer in an 8-byte buffer and returns that buffer.
static void encodeDouble(double value, byte[] buffer, int offset)
          Converts a double value to a long and stores that long value as a big-endian 64-bit integer into buffer at specified offset.
static byte[] encodeFloat(float value)
          Converts a float value to an int and stores that int value as a big-endian 32-bit integer in a 4-byte buffer and returns that buffer.
static void encodeFloat(float value, byte[] buffer, int offset)
          Converts a float value to an int and stores that int value as a big-endian 32-bit integer in the specified buffer at a specified offset.
static byte[] encodeInt(int value)
          Encodes an int as a big-endian 32-bit integer into a 4-byte buffer and returns the buffer.
static void encodeInt(int value, byte[] buffer, int offset)
          Encodes an int as a big-endian 32-bit integer into buffer at the specified offset.
static byte[] encodeLong(long value)
          Encodes a long value as a big-endian 64-bit integer into a 8-byte buffer and returns the buffer.
static void encodeLong(long value, byte[] buffer, int offset)
          Encodes a long value as a big-endian 64-bit integer into a buffer at specified offset.
static byte[] encodeShort(short value)
          Encodes a short value as a big-endian 16-bit integer into a 2-byte buffer and returns that buffer.
static void encodeShort(short value, byte[] buffer, int offset)
          Encodes a short value as a big-endian 16-bit integer into a buffer at the specified offset.
static byte[] encodeString(String str)
          Appends a null character to the string and returns a buffer containing the encoded string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JEncodingHelpers

public JEncodingHelpers()
Method Detail

encodeBoolean

public static byte[] encodeBoolean(boolean value)
Encodes a boolean value as a big-endian 32-bit integer in a 4-byte buffer and returns the buffer.

Parameters:
value - Value to encode
Returns:
Buffer with encoded value

encodeBoolean

public static void encodeBoolean(boolean value,
                                 byte[] buffer,
                                 int offset)
Encodes a boolean value as a big-endian 32-bit integer into the specified buffer at the specified offset.

Parameters:
value - Value to encode
buffer - Buffer to store value in
offset - Offset in buffer

decodeBoolean

public static boolean decodeBoolean(byte[] buffer)
Decodes a big-endian 32-bit integer in a buffer into a boolean.

Parameters:
buffer - Buffer containing encoded value
Returns:
Decoded value

decodeBoolean

public static boolean decodeBoolean(byte[] buffer,
                                    int offset)
Decodes a big-endian 32-bit integer in a 4-byte buffer at the specified offset int a boolean value.

Parameters:
buffer - Buffer containing encoded value
offset - Offset in buffer
Returns:
Decoded value

encodeByte

public static byte[] encodeByte(int value)
Encodes a byte in a buffer and returns the buffer.

Parameters:
value - Value to encode
Returns:
Buffer with encoded value

encodeByte

public static void encodeByte(int value,
                              byte[] buffer,
                              int offset)
Encodes a byte into a buffer at the specified offset.

Parameters:
value - Value to encode
buffer - Buffer to store value in
offset - Offset in buffer

decodeByte

public static byte decodeByte(byte[] buffer)
Decodes a byte from a buffer.

Parameters:
buffer - Buffer containing encoded value
Returns:
Decoded value.

decodeByte

public static byte decodeByte(byte[] buffer,
                              int offset)
Decodes a byte from a buffer at the specified offset.

Parameters:
buffer - Buffer containing encoded value
offset - Offset in buffer
Returns:
Decoded value.

encodeChar

public static byte[] encodeChar(char value)
Encodes a char value as a big-endian 16-bit integer into a 2-byte buffer and returns the buffer.

Parameters:
value - Value to encode
Returns:
Buffer with encoded value

encodeChar

public static void encodeChar(char value,
                              byte[] buffer,
                              int offset)
Encodes a char value as a big-endian 16-bit integer into a buffer at the specified offset.

Parameters:
value - Value to encode
buffer - Buffer to encode value in
offset - Offset in buffer

decodeChar

public static char decodeChar(byte[] buffer)
Decodes a big-endian 16-bit integer in a buffer into a char value.

Parameters:
buffer - Buffer containing encoded value
Returns:
Decoded value.

decodeChar

public static char decodeChar(byte[] buffer,
                              int offset)
Decodes a big-endian 16-bit integer in a buffer at the specified offset into a char value.

Parameters:
buffer - Buffer containing encoded value
offset - Offset in buffer
Returns:
Decoded value.

encodeDouble

public static byte[] encodeDouble(double value)
Converts a double value to a long and stores that long value as a big-endian 64-bit integer in an 8-byte buffer and returns that buffer.

Parameters:
value - Value to encode
Returns:
Buffer with encoded value

encodeDouble

public static void encodeDouble(double value,
                                byte[] buffer,
                                int offset)
Converts a double value to a long and stores that long value as a big-endian 64-bit integer into buffer at specified offset.

Parameters:
value - Value to encode
buffer - Buffer to store value in
offset - Offset in buffer

decodeDouble

public static double decodeDouble(byte[] buffer)
Decodes a big-endian 64-bit integer stored in buffer into a long value and converts that to a double value, which is returned.

Parameters:
buffer - Buffer containing encoded value
Returns:
Decoded value

decodeDouble

public static double decodeDouble(byte[] buffer,
                                  int offset)
Decodes a big-endian 64-bit integer stored in buffer at specified offset into a long value and converts that to a double value, which is returned.

Parameters:
buffer - Buffer containing encoded value
offset - Offset in buffer
Returns:
Decoded value

encodeFloat

public static byte[] encodeFloat(float value)
Converts a float value to an int and stores that int value as a big-endian 32-bit integer in a 4-byte buffer and returns that buffer.

Parameters:
value - Value to encode
Returns:
Buffer with encoded value

encodeFloat

public static void encodeFloat(float value,
                               byte[] buffer,
                               int offset)
Converts a float value to an int and stores that int value as a big-endian 32-bit integer in the specified buffer at a specified offset.

Parameters:
value - Value to encode
buffer - Buffer to store value in
offset - Offset in buffer

decodeFloat

public static float decodeFloat(byte[] buffer)
Decodes a big-endian 32-bit integer stored in buffer into an int value and converts that to a float value, which is returned.

Parameters:
buffer - Buffer containing encoded value
Returns:
Decoded value

decodeFloat

public static float decodeFloat(byte[] buffer,
                                int offset)
Decodes a big-endian 32-bit integer stored in buffer at specified offset into an int value and converts that to a float value, which is returned.

Parameters:
buffer - Buffer containing encoded value
offset - Offset in buffer
Returns:
Decoded value

encodeInt

public static byte[] encodeInt(int value)
Encodes an int as a big-endian 32-bit integer into a 4-byte buffer and returns the buffer.

Parameters:
value - Value to encode
Returns:
Buffer with encoded value

encodeInt

public static void encodeInt(int value,
                             byte[] buffer,
                             int offset)
Encodes an int as a big-endian 32-bit integer into buffer at the specified offset.

Parameters:
value - Value to encode
buffer - Buffer to store value in
offset - Offset in buffer

decodeInt

public static int decodeInt(byte[] buffer)
Decodes a big-endian 32-bit integer stored in buffer into an int value.

Parameters:
buffer - Buffer containing encoded value
Returns:
Decoded value

decodeInt

public static int decodeInt(byte[] buffer,
                            int offset)
Decodes a big-endian 32-bit integer stored in buffer at specified offset into an int value.

Parameters:
buffer - Buffer containing encoded value
offset - Offset in buffer
Returns:
Decoded value

encodeLong

public static byte[] encodeLong(long value)
Encodes a long value as a big-endian 64-bit integer into a 8-byte buffer and returns the buffer.

Parameters:
value - Value to encode
Returns:
Buffer with encoded value

encodeLong

public static void encodeLong(long value,
                              byte[] buffer,
                              int offset)
Encodes a long value as a big-endian 64-bit integer into a buffer at specified offset.

Parameters:
value - Value to encode
buffer - Buffer to store value in
offset - Offset in buffer

decodeLong

public static long decodeLong(byte[] buffer)
Decodes a big-endian 64-bit integer stored in buffer into a long value.

Parameters:
buffer - Buffer containing encoded value
Returns:
Decoded value

decodeLong

public static long decodeLong(byte[] buffer,
                              int offset)
Decodes a big-endian 64-bit integer stored in buffer at specified offset into a long value.

Parameters:
buffer - Buffer containing encoded value
offset - Offset in buffer
Returns:
Decoded value

encodeShort

public static byte[] encodeShort(short value)
Encodes a short value as a big-endian 16-bit integer into a 2-byte buffer and returns that buffer.

Parameters:
value - Value to encode
Returns:
Buffer with encoded value

encodeShort

public static void encodeShort(short value,
                               byte[] buffer,
                               int offset)
Encodes a short value as a big-endian 16-bit integer into a buffer at the specified offset.

Parameters:
value - Value to encode
buffer - Buffer to store value in
offset - Offset in buffer

decodeShort

public static short decodeShort(byte[] buffer)
Decodes a big-endian 16-bit integer stored in buffer into a short value.

Parameters:
buffer - Buffer containing encoded value
Returns:
Decoded value

decodeShort

public static short decodeShort(byte[] buffer,
                                int offset)
Decodes a big-endian 16-bit integer stored in buffer at specified offset into a short value.

Parameters:
buffer - Buffer containing encoded value
offset - Offset in buffer
Returns:
Decoded value

encodeString

public static byte[] encodeString(String str)
Appends a null character to the string and returns a buffer containing the encoded string. The purpose of the null character is compatibility with federates written in C++.

Parameters:
str - String to encode
Returns:
Buffer with encoded string

decodeString

public static String decodeString(byte[] buffer)
Decodes a string from a buffer and strips the final null character.

Parameters:
buffer - Buffer with encoded string
Returns:
Decoded string

copyright The Portico Project 2008.