org.jboss.netty.handler.codec.marshalling

## Class MarshallingDecoder

- java.lang.Object
- - org.jboss.netty.channel.SimpleChannelUpstreamHandler
  - - org.jboss.netty.handler.codec.frame.FrameDecoder
    - - org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder
      - - org.jboss.netty.handler.codec.marshalling.MarshallingDecoder

- All Implemented Interfaces:
    ChannelHandler, ChannelUpstreamHandler, LifeCycleAwareChannelHandler

      public class MarshallingDecoder
      extends LengthFieldBasedFrameDecoder

  Decoder which MUST be used with `MarshallingEncoder`. A `LengthFieldBasedFrameDecoder` which use an `Unmarshaller` to read the Object out of the `ChannelBuffer`.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler

      `ChannelHandler.Sharable`

  - ### Field Summary

    - ### Fields inherited from class org.jboss.netty.handler.codec.frame.FrameDecoder

      `cumulation, DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MarshallingDecoder(UnmarshallerProvider provider)` Creates a new decoder whose maximum object size is `1048576` bytes.
    `MarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize)` Creates a new decoder with the specified maximum object size.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Object` | `decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)` Decodes the received packets so far into a frame.
    `protected ChannelBuffer` | `extractFrame(ChannelBuffer buffer, int index, int length)` Extract the sub-region of the specified buffer.

    - ### Methods inherited from class org.jboss.netty.handler.codec.frame.FrameDecoder

      `actualReadableBytes, afterAdd, afterRemove, appendToCumulation, beforeAdd, beforeRemove, channelClosed, channelDisconnected, cleanup, decodeLast, exceptionCaught, getMaxCumulationBufferCapacity, getMaxCumulationBufferComponents, internalBuffer, isUnfold, messageReceived, newCumulationBuffer, replace, setMaxCumulationBufferCapacity, setMaxCumulationBufferComponents, setUnfold, unfoldAndFireMessageReceived, updateCumulation`

    - ### Methods inherited from class org.jboss.netty.channel.SimpleChannelUpstreamHandler

      `channelBound, channelConnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, handleUpstream, writeComplete`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MarshallingDecoder

          public MarshallingDecoder(UnmarshallerProvider provider)

      Creates a new decoder whose maximum object size is `1048576` bytes. If the size of the received object is greater than `1048576` bytes, a `StreamCorruptedException` will be raised.

    - #### MarshallingDecoder

          public MarshallingDecoder(UnmarshallerProvider provider,
                            int maxObjectSize)

      Creates a new decoder with the specified maximum object size.
      Parameters:
        `maxObjectSize` - the maximum byte length of the serialized object. if the length of the received object is greater than this value, `TooLongFrameException` will be raised.

  - ### Method Detail

    - #### decode

          protected Object decode(ChannelHandlerContext ctx,
                      Channel channel,
                      ChannelBuffer buffer)
                           throws Exception

      Description copied from class: `FrameDecoder`
      Decodes the received packets so far into a frame.
      Overrides:
        `decode` in class `LengthFieldBasedFrameDecoder`
      Parameters:
        `ctx` - the context of this handler
        `channel` - the current channel
        `buffer` - the cumulative buffer of received packets so far. Note that the buffer might be empty, which means you should not make an assumption that the buffer contains at least one byte in your decoder implementation.
      Returns:
        the decoded frame if a full frame was received and decoded. `null` if there's not enough data in the buffer to decode a frame.
      Throws:
        `Exception`

    - #### extractFrame

          protected ChannelBuffer extractFrame(ChannelBuffer buffer,
                                   int index,
                                   int length)

      Description copied from class: `LengthFieldBasedFrameDecoder`
      Extract the sub-region of the specified buffer. This method is called by `LengthFieldBasedFrameDecoder.decode(ChannelHandlerContext, Channel, ChannelBuffer)` for each frame. The default implementation returns a copy of the sub-region. For example, you could override this method to use an alternative `ChannelBufferFactory`.

      If you are sure that the frame and its content are not accessed after the current `LengthFieldBasedFrameDecoder.decode(ChannelHandlerContext, Channel, ChannelBuffer)` call returns, you can even avoid memory copy by returning the sliced sub-region (i.e. `return buffer.slice(index, length)`). It's often useful when you convert the extracted frame into an object. Refer to the source code of `ObjectDecoder` to see how this method is overridden to avoid memory copy.

      Overrides:
        `extractFrame` in class `LengthFieldBasedFrameDecoder`

Copyright © 2008-2012 The Netty Project. All Rights Reserved.