step.encoding
Class DeltaIntStrategy

java.lang.Object
  |
  +--step.encoding.Encoder
        |
        +--step.encoding.Strategy
              |
              +--step.encoding.RegularValueStrategy
                    |
                    +--step.encoding.DeltaIntStrategy
Direct Known Subclasses:
PDeltaIntStrategy

public class DeltaIntStrategy
extends RegularValueStrategy

Assume that the next (integer) value is relatively close to the last, and only transmit on the difference from the last value.

NOTE: Although values may be more than 4 bytes (i.e. long), their difference must be in the int range. Otherwise, the behavior of this encoder is undefined.

Algorithm:

 delta := current - last;
 if |delta| <= threshold
     then -> delta
     else -> meta:IrregularValueEvent, current
 
Credit: A. Samples (Mache)

See Also:
StepInt

Field Summary
static String STRATEGY_NAME
           
 
Fields inherited from class step.encoding.RegularValueStrategy
_nextIsRegular
 
Fields inherited from class step.encoding.Strategy
_baseEncoder
 
Constructor Summary
DeltaIntStrategy(Encoder baseEncoder, int threshold)
          Create a new "delta" strategy.
 
Method Summary
 StepObject decode(DecodeContext context)
          Decode a value.
 void dump(int level)
           
 void encode(StepObject o, EncodeContext context)
          Encode an integer value.
 
Methods inherited from class step.encoding.RegularValueStrategy
setNextIsRegular
 
Methods inherited from class step.encoding.Strategy
baseDecode, baseEncode, eventMessage
 
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

STRATEGY_NAME

public static final String STRATEGY_NAME
See Also:
Constant Field Values
Constructor Detail

DeltaIntStrategy

public DeltaIntStrategy(Encoder baseEncoder,
                        int threshold)
Create a new "delta" strategy.

Parameters:
baseEncoder - the encoder to defer to for irregular values
threshold - the maximum (absolute) delta value to encode
Throws:
IllegalArgumentException - if the threshold is < 0.
Method Detail

encode

public void encode(StepObject o,
                   EncodeContext context)
            throws EncoderException,
                   IOException
Encode an integer value.

Specified by:
encode in class Encoder
Throws:
EncoderException - if the value is not a StepInt.
IOException - if the encode operation encountered an I/O failure.

decode

public StepObject decode(DecodeContext context)
                  throws EncoderException,
                         IOException
Description copied from class: Encoder
Decode a 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.

dump

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