com.kuka.comm.codec.bytebuffer
Class LengthDecoder

java.lang.Object
  extended by com.kuka.comm.codec.Decoder<ByteBuffer,ByteBuffer>
      extended by com.kuka.comm.codec.bytebuffer.LengthDecoder

public final class LengthDecoder
extends Decoder<ByteBuffer,ByteBuffer>

Decoder that reads length information for a variable or fixed length payload and extracts the payload. If the remaining buffer contains enough bytes, the payload is passed on to the next decoder.


Constructor Summary
LengthDecoder(int fixedLength)
          Creates a new decoder for fixed length payload.
LengthDecoder(LengthFieldType type)
          Creates a new decoder for variable length payload.
 
Method Summary
protected  ByteBuffer decodeImpl(ByteBuffer 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

LengthDecoder

public LengthDecoder(LengthFieldType type)
Creates a new decoder for variable length payload.

Parameters:
type - the type of the length field, must not be null
Throws:
IllegalArgumentException - if the length type is null

LengthDecoder

public LengthDecoder(int fixedLength)
Creates a new decoder for fixed length payload.

Parameters:
fixedLength - the fixed length of the payload, must be greater than 0
Throws:
IllegalArgumentException - if the fixed length is less or equal than 0
Method Detail

decodeImpl

protected ByteBuffer decodeImpl(ByteBuffer 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<ByteBuffer,ByteBuffer>
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.