com.kuka.comm.codec
Class SwitchDecoder<M,S,I,O>

java.lang.Object
  extended by com.kuka.comm.codec.Decoder<M,O>
      extended by com.kuka.comm.codec.SwitchDecoder<M,S,I,O>
Type Parameters:
M - the initial input type for the switch info decoder
S - the type of the SwitchInfo token
I - the input type of the actual decoder
O - the output type of the actual decoder

public final class SwitchDecoder<M,S,I,O>
extends Decoder<M,O>

A SwitchDecoder selects a Decoder decoder to decode the input based on the content of the input. It is provided with a single switch info Decoder to decode the SwitchInfo of a given input. Based on the decoded SwitchInfo the actual decoder will be selected among the decoders provided by the user and it will be used to decode the input given in the said SwitchInfo.


Constructor Summary
SwitchDecoder(Decoder<M,SwitchInfo<S,I>> switchInfoDecoder)
          Creates a new DecoderSwitch that uses the given Decoder to decode the SwitchInfo of a given input.
 
Method Summary
 SwitchDecoder<M,S,I,O> addDecoder(S switchToken, Decoder<I,O> decoder)
          Adds a Decoder to this DecoderSwitch and associates it with the given token.
protected  O decodeImpl(M in)
          Realization of the decoding method to be implemented in subclasses.
 
Methods inherited from class com.kuka.comm.codec.Decoder
concat, decode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwitchDecoder

public SwitchDecoder(Decoder<M,SwitchInfo<S,I>> switchInfoDecoder)
Creates a new DecoderSwitch that uses the given Decoder to decode the SwitchInfo of a given input. Based on the decoded SwitchInfo the actual decoder will be selected and it will be used to decode the input given in the said SwitchInfo.

Parameters:
switchInfoDecoder - The decoder to decode the SwitchInfo.
Method Detail

addDecoder

public SwitchDecoder<M,S,I,O> addDecoder(S switchToken,
                                         Decoder<I,O> decoder)
Adds a Decoder to this DecoderSwitch and associates it with the given token. This decoder will be selected whenever the decoded SwitchInfo contains the given token. A switch token can only be associated with one decoder. If the given token is already known, the this decoder will replace the previously set decoder.

Parameters:
switchToken - the switch token
decoder - the decoder
Returns:
this object

decodeImpl

protected O decodeImpl(M in)
                throws DecoderException
Description copied from class: Decoder
Realization of the decoding method to be implemented in subclasses. This method will be called by the Decoder.decode(Object) method.

Return null to indicate that the decoder could not finish its job (e.g. because the input was incomplete). The decoding will be cancelled, i.e. concatenated decoders coming after this decoder will not be called, and the decoding process will restart, when more data is available. Throw an exception to indicate that an error occurred during decoding. The data read so far will be discarded.

Specified by:
decodeImpl in class Decoder<M,O>
Parameters:
in - the input for this decoder, usually the message to be decoded
Returns:
the decoded message, or null if the input was incomplete
Throws:
DecoderException - if an error occurred during decoding


Copyright © 2019. All rights reserved.