com.flagstone.transform.coder
Class Coder

java.lang.Object
  extended by com.flagstone.transform.coder.Coder

public final class Coder
extends Object

Coder contains constants and utility functions used by the various classes for encoding and decoding.


Field Summary
static int ACTION_HEADER
          Length, in bytes, of type and length fields of an encoded action.
static int ALIGN_BYTE1
          Number of bits to shift when aligning a value to the second byte.
static int ALIGN_BYTE2
          Number of bits to shift when aligning a value to the third byte.
static int ALIGN_BYTE3
          Number of bits to shift when aligning a value to the fourth byte.
static int ALIGN_NIB1
          Number of bits to shift when aligning bits 4-7 to positions 0-3.
static int ALIGN_NIB2
          Number of bits to shift when aligning bits 8-11 to positions 0-3.
static int ALIGN_NIB3
          Number of bits to shift when aligning bits 12-15 to positions 0-3.
static int BIT0
          Mask for getting and setting bit 0 of a word.
static int BIT1
          Mask for getting and setting bit 1 of a word.
static int BIT10
          Mask for getting and setting bit 10 of a word.
static int BIT15
          Mask for getting and setting bit 15 of a word.
static int BIT2
          Mask for getting and setting bit 2 of a word.
static int BIT3
          Mask for getting and setting bit 3 of a word.
static int BIT4
          Mask for getting and setting bit 4 of a word.
static int BIT5
          Mask for getting and setting bit 5 of a word.
static int BIT6
          Mask for getting and setting bit 6 of a word.
static int BIT7
          Mask for getting and setting bit 7 of a word.
static int HEADER_LIMIT
          The maximum length in bytes of an encoded object before the length must be encoded using a 32-bit integer.
static int IS_EXTENDED
          Value used to indicate that the length of an object has been encoded as a 32-bit integer following the header for the MovieTag.
static int LENGTH_FIELD
          Bit mask for extracting the length field from the header word.
static int LENGTH_FIELD_SIZE
          The number of bits used to encode the length field when the length is less than the maximum length of 62.
static int LONG_HEADER
          Number of bytes occupied by the header when the size of the encoded object is greater than 62 bytes.
static int LOWEST10
          Bit mask for the lowest 5 bits in a word.
static int LOWEST12
          Bit mask for the lowest 5 bits in a word.
static int LOWEST15
          Bit mask for the lowest 5 bits in a word.
static int LOWEST3
          Bit mask for the lowest 5 bits in a word.
static int LOWEST5
          Bit mask for the lowest 5 bits in a word.
static int LOWEST7
          Bit mask for the lowest 5 bits in a word.
static int NIB0
          Mask for accessing bits 0-3 of a word.
static int NIB1
          Mask for accessing bits 4-7 of a word.
static int NIB2
          Mask for accessing bits 8-11 of a word.
static int NIB3
          Mask for accessing bits 12-15 of a word.
static int PAIR0
          Mask for accessing bits 0 & 1 of a byte.
static int PAIR1
          Mask for accessing bits 2 & 3 of a byte.
static int PAIR2
          Mask for accessing bits 0 & 1 of a byte.
static int PAIR3
          Mask for accessing bits 2 & 3 of a byte.
static float SCALE_14
          Factor for converting floats to/from 15.15 fixed-point values.
static float SCALE_16
          Factor for converting floats to/from 16.16 fixed-point values.
static float SCALE_8
          Factor for converting floats to/from 8.8 fixed-point values.
static int SHORT_HEADER
          Number of bytes occupied by the header when the size of the encoded object is 62 bytes or less.
static int SHORT_MAX
          Maximum value that can be stored in a 16-bit signed field.
static int SHORT_MIN
          Minimum value that can be stored in a 16-bit signed field.
static int TO_LOWER_BYTE
          Right shift to move upper byte of 16-bit word to lower.
static int TO_LOWER_NIB
          Right shift to move upper byte of 16-bit word to lower.
static int TO_UPPER_BYTE
          Left shift to move lower byte of 16-bit word to upper.
static int TO_UPPER_NIB
          Left shift to move lower byte of 16-bit word to upper.
static int USHORT_MAX
          Maximum value that can be stored in a 16-bit unsigned field.
static int VAR_INT_MAX
          The maximum value for each byte in a variable length integer.
static int VAR_INT_SHIFT
          Shift when converting to a variable length integer.
 
Method Summary
static int maxSize(int... values)
          Returns the minimum number of bits required to encode all the signed values in an array as a set of bit fields with the same size.
static int size(int value)
          Calculates the minimum number of bits required to encoded a signed integer in a bit field.
static int sizeVariableU32(int value)
          Calculate minimum number of bytes a 32-bit unsigned integer can be encoded in.
static int unsignedSize(int value)
          Calculates the minimum number of bits required to encoded an unsigned integer in a bit field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BIT0

public static final int BIT0
Mask for getting and setting bit 0 of a word.

See Also:
Constant Field Values

BIT1

public static final int BIT1
Mask for getting and setting bit 1 of a word.

See Also:
Constant Field Values

BIT2

public static final int BIT2
Mask for getting and setting bit 2 of a word.

See Also:
Constant Field Values

BIT3

public static final int BIT3
Mask for getting and setting bit 3 of a word.

See Also:
Constant Field Values

BIT4

public static final int BIT4
Mask for getting and setting bit 4 of a word.

See Also:
Constant Field Values

BIT5

public static final int BIT5
Mask for getting and setting bit 5 of a word.

See Also:
Constant Field Values

BIT6

public static final int BIT6
Mask for getting and setting bit 6 of a word.

See Also:
Constant Field Values

BIT7

public static final int BIT7
Mask for getting and setting bit 7 of a word.

See Also:
Constant Field Values

BIT10

public static final int BIT10
Mask for getting and setting bit 10 of a word.

See Also:
Constant Field Values

BIT15

public static final int BIT15
Mask for getting and setting bit 15 of a word.

See Also:
Constant Field Values

NIB0

public static final int NIB0
Mask for accessing bits 0-3 of a word.

See Also:
Constant Field Values

NIB1

public static final int NIB1
Mask for accessing bits 4-7 of a word.

See Also:
Constant Field Values

NIB2

public static final int NIB2
Mask for accessing bits 8-11 of a word.

See Also:
Constant Field Values

NIB3

public static final int NIB3
Mask for accessing bits 12-15 of a word.

See Also:
Constant Field Values

PAIR0

public static final int PAIR0
Mask for accessing bits 0 & 1 of a byte.

See Also:
Constant Field Values

PAIR1

public static final int PAIR1
Mask for accessing bits 2 & 3 of a byte.

See Also:
Constant Field Values

PAIR2

public static final int PAIR2
Mask for accessing bits 0 & 1 of a byte.

See Also:
Constant Field Values

PAIR3

public static final int PAIR3
Mask for accessing bits 2 & 3 of a byte.

See Also:
Constant Field Values

LOWEST3

public static final int LOWEST3
Bit mask for the lowest 5 bits in a word.

See Also:
Constant Field Values

LOWEST5

public static final int LOWEST5
Bit mask for the lowest 5 bits in a word.

See Also:
Constant Field Values

LOWEST7

public static final int LOWEST7
Bit mask for the lowest 5 bits in a word.

See Also:
Constant Field Values

LOWEST10

public static final int LOWEST10
Bit mask for the lowest 5 bits in a word.

See Also:
Constant Field Values

LOWEST12

public static final int LOWEST12
Bit mask for the lowest 5 bits in a word.

See Also:
Constant Field Values

LOWEST15

public static final int LOWEST15
Bit mask for the lowest 5 bits in a word.

See Also:
Constant Field Values

TO_LOWER_BYTE

public static final int TO_LOWER_BYTE
Right shift to move upper byte of 16-bit word to lower.

See Also:
Constant Field Values

TO_UPPER_BYTE

public static final int TO_UPPER_BYTE
Left shift to move lower byte of 16-bit word to upper.

See Also:
Constant Field Values

TO_LOWER_NIB

public static final int TO_LOWER_NIB
Right shift to move upper byte of 16-bit word to lower.

See Also:
Constant Field Values

TO_UPPER_NIB

public static final int TO_UPPER_NIB
Left shift to move lower byte of 16-bit word to upper.

See Also:
Constant Field Values

USHORT_MAX

public static final int USHORT_MAX
Maximum value that can be stored in a 16-bit unsigned field.

See Also:
Constant Field Values

SHORT_MIN

public static final int SHORT_MIN
Minimum value that can be stored in a 16-bit signed field.

See Also:
Constant Field Values

SHORT_MAX

public static final int SHORT_MAX
Maximum value that can be stored in a 16-bit signed field.

See Also:
Constant Field Values

ALIGN_BYTE1

public static final int ALIGN_BYTE1
Number of bits to shift when aligning a value to the second byte.

See Also:
Constant Field Values

ALIGN_BYTE2

public static final int ALIGN_BYTE2
Number of bits to shift when aligning a value to the third byte.

See Also:
Constant Field Values

ALIGN_BYTE3

public static final int ALIGN_BYTE3
Number of bits to shift when aligning a value to the fourth byte.

See Also:
Constant Field Values

ALIGN_NIB1

public static final int ALIGN_NIB1
Number of bits to shift when aligning bits 4-7 to positions 0-3.

See Also:
Constant Field Values

ALIGN_NIB2

public static final int ALIGN_NIB2
Number of bits to shift when aligning bits 8-11 to positions 0-3.

See Also:
Constant Field Values

ALIGN_NIB3

public static final int ALIGN_NIB3
Number of bits to shift when aligning bits 12-15 to positions 0-3.

See Also:
Constant Field Values

SCALE_8

public static final float SCALE_8
Factor for converting floats to/from 8.8 fixed-point values.

See Also:
Constant Field Values

SCALE_14

public static final float SCALE_14
Factor for converting floats to/from 15.15 fixed-point values.

See Also:
Constant Field Values

SCALE_16

public static final float SCALE_16
Factor for converting floats to/from 16.16 fixed-point values.

See Also:
Constant Field Values

VAR_INT_MAX

public static final int VAR_INT_MAX
The maximum value for each byte in a variable length integer.

See Also:
Constant Field Values

VAR_INT_SHIFT

public static final int VAR_INT_SHIFT
Shift when converting to a variable length integer.

See Also:
Constant Field Values

LENGTH_FIELD

public static final int LENGTH_FIELD
Bit mask for extracting the length field from the header word.

See Also:
Constant Field Values

LENGTH_FIELD_SIZE

public static final int LENGTH_FIELD_SIZE
The number of bits used to encode the length field when the length is less than the maximum length of 62.

See Also:
Constant Field Values

IS_EXTENDED

public static final int IS_EXTENDED
Value used to indicate that the length of an object has been encoded as a 32-bit integer following the header for the MovieTag.

See Also:
Constant Field Values

SHORT_HEADER

public static final int SHORT_HEADER
Number of bytes occupied by the header when the size of the encoded object is 62 bytes or less.

See Also:
Constant Field Values

HEADER_LIMIT

public static final int HEADER_LIMIT
The maximum length in bytes of an encoded object before the length must be encoded using a 32-bit integer.

See Also:
Constant Field Values

LONG_HEADER

public static final int LONG_HEADER
Number of bytes occupied by the header when the size of the encoded object is greater than 62 bytes.

See Also:
Constant Field Values

ACTION_HEADER

public static final int ACTION_HEADER
Length, in bytes, of type and length fields of an encoded action.

See Also:
Constant Field Values
Method Detail

unsignedSize

public static int unsignedSize(int value)
Calculates the minimum number of bits required to encoded an unsigned integer in a bit field.

Parameters:
value - the unsigned value to be encoded.
Returns:
the number of bits required to encode the value.

size

public static int size(int value)
Calculates the minimum number of bits required to encoded a signed integer in a bit field.

Parameters:
value - the signed value to be encoded.
Returns:
the number of bits required to encode the value.

maxSize

public static int maxSize(int... values)
Returns the minimum number of bits required to encode all the signed values in an array as a set of bit fields with the same size.

Parameters:
values - an array of signed integers.
Returns:
the minimum number of bits required to encode each of the values.

sizeVariableU32

public static int sizeVariableU32(int value)
Calculate minimum number of bytes a 32-bit unsigned integer can be encoded in.

Parameters:
value - an integer containing the value to be written.
Returns:
the number of bytes required to encode the integer.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.