step.encoding
Class IntEncoder

java.lang.Object
  |
  +--step.encoding.Encoder
        |
        +--step.encoding.IntEncoder

public class IntEncoder
extends Encoder

An encoder for STEP int objects that uses a specific number of bytes.

Bytes are written in LITTLE endian (least significant -> most significant) order. If the required number of bits is greater than the allowed size, either an EncoderMessageEvent signals the deviant size value or an exception is thrown if the size is fixed. If the number of bytes is too small, the value is padded.

See Also:
StepInt, CreepIntEncoder

Field Summary
static int ELASTIC_SIZE
           
static int FIXED_SIZE
           
static int GROW_SIZE
           
(package private) static int LONG_SIZE
           
 
Constructor Summary
IntEncoder(String name, int size, int resize, boolean unsigned, EncoderFactory factory)
          Create a new encoder for STEP int types.
 
Method Summary
 StepObject decode(DecodeContext context)
          Decode a STEP int value.
 void dump(int level)
           
 void encode(StepObject o, EncodeContext context)
          Encode the given STEP int value.
protected  void eventMessage(String msg)
          Send a text message to this encoder.
 
Methods inherited from class step.encoding.Encoder
getFactory, getName, indent, makeFieldName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIXED_SIZE

public static final int FIXED_SIZE
See Also:
Constant Field Values

ELASTIC_SIZE

public static final int ELASTIC_SIZE
See Also:
Constant Field Values

GROW_SIZE

public static final int GROW_SIZE
See Also:
Constant Field Values

LONG_SIZE

static final int LONG_SIZE
See Also:
Constant Field Values
Constructor Detail

IntEncoder

public IntEncoder(String name,
                  int size,
                  int resize,
                  boolean unsigned,
                  EncoderFactory factory)
Create a new encoder for STEP int types.

Parameters:
name - the name for this encoder.
size - the (minimum) number of bytes to use for encoding
resize - the policy regarding size changes. One of FIXED_SIZE, ELASTIC_SIZE or GROW_SIZE.
unsigned - true if encoded/decoded values are always >= 0
factory - the EncoderFactory used to create this encoder
Throws:
IllegalArgumentException - if the size or resize values are invalid.
Method Detail

encode

public void encode(StepObject o,
                   EncodeContext context)
            throws EncoderException,
                   IOException
Encode the given STEP int value.

Specified by:
encode in class Encoder
Throws:
EncoderException - if
  • the value was not a StepInt.
  • the "unsigned" option was set and the value was negative
  • the "fixed" resize policy was set and the value requires too many bytes to encode
IOException - if the encode operation encountered an I/O failure.

decode

public StepObject decode(DecodeContext context)
                  throws EncoderException,
                         IOException
Decode a STEP int value.

Specified by:
decode in class Encoder
Throws:
IOException - if the decode operation encountered an I/O failure.
EncoderException - if the decode operation encountered an error.

eventMessage

protected void eventMessage(String msg)
Description copied from class: Encoder
Send a text message to this encoder.

In general, messages are intended for the decoding process.

The default behavior is to ignore the message.

Overrides:
eventMessage in class Encoder
See Also:
EncoderMessageEvent

dump

public void dump(int level)
Specified by:
dump in class Encoder