Home / Class/ MarshallingDecoder Class — netty Architecture

MarshallingDecoder Class — netty Architecture

Architecture documentation for the MarshallingDecoder class in MarshallingDecoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  41b6ecfe_a3e0_b9ab_1c48_efc8411af770["MarshallingDecoder"]
  972711ac_3bb1_bea9_a131_5f2bbb73aead["MarshallingDecoder.java"]
  41b6ecfe_a3e0_b9ab_1c48_efc8411af770 -->|defined in| 972711ac_3bb1_bea9_a131_5f2bbb73aead
  3c7480bc_6ec1_055b_c0e7_248770a9ce00["MarshallingDecoder()"]
  41b6ecfe_a3e0_b9ab_1c48_efc8411af770 -->|method| 3c7480bc_6ec1_055b_c0e7_248770a9ce00
  e748c351_00f4_f8f5_cf22_90d161ab17ed["Object()"]
  41b6ecfe_a3e0_b9ab_1c48_efc8411af770 -->|method| e748c351_00f4_f8f5_cf22_90d161ab17ed
  8747d81b_53b1_4a48_6950_69f855a9b2e7["ByteBuf()"]
  41b6ecfe_a3e0_b9ab_1c48_efc8411af770 -->|method| 8747d81b_53b1_4a48_6950_69f855a9b2e7

Relationship Graph

Source Code

codec-marshalling/src/main/java/io/netty/handler/codec/marshalling/MarshallingDecoder.java lines 33–87

public class MarshallingDecoder extends LengthFieldBasedFrameDecoder {

    private final UnmarshallerProvider provider;

    /**
     * Creates a new decoder whose maximum object size is {@code 1048576}
     * bytes.  If the size of the received object is greater than
     * {@code 1048576} bytes, a {@link StreamCorruptedException} will be
     * raised.
     *
     */
    public MarshallingDecoder(UnmarshallerProvider provider) {
        this(provider, 1048576);
    }

    /**
     * Creates a new decoder with the specified maximum object size.
     *
     * @param maxObjectSize  the maximum byte length of the serialized object.
     *                       if the length of the received object is greater
     *                       than this value, {@link TooLongFrameException}
     *                       will be raised.
     */
    public MarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize) {
        super(maxObjectSize, 0, 4, 0, 4);
        this.provider = provider;
    }

    @Override
    protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
        ByteBuf frame = (ByteBuf) super.decode(ctx, in);
        if (frame == null) {
            return null;
        }

        Unmarshaller unmarshaller = provider.getUnmarshaller(ctx);
        ByteInput input = new ChannelBufferByteInput(frame);

        try {
            unmarshaller.start(input);
            Object obj = unmarshaller.readObject();
            unmarshaller.finish();
            return obj;
        } finally {
            // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are
            // readable. This helps to be sure that we do not leak resource
            unmarshaller.close();
        }
    }

    @Override
    protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
        return buffer.slice(index, length);
    }
}

Frequently Asked Questions

What is the MarshallingDecoder class?
MarshallingDecoder is a class in the netty codebase, defined in codec-marshalling/src/main/java/io/netty/handler/codec/marshalling/MarshallingDecoder.java.
Where is MarshallingDecoder defined?
MarshallingDecoder is defined in codec-marshalling/src/main/java/io/netty/handler/codec/marshalling/MarshallingDecoder.java at line 33.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free