Home / Class/ ReplayingDecoder Class — netty Architecture

ReplayingDecoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  acf0308a_b3b3_8956_f20c_c96385b17313["ReplayingDecoder"]
  dcdfc51b_78e2_bbff_a9c7_cb82182af2e7["ReplayingDecoder.java"]
  acf0308a_b3b3_8956_f20c_c96385b17313 -->|defined in| dcdfc51b_78e2_bbff_a9c7_cb82182af2e7
  37e4c011_229f_2a4c_6ccd_33f12266cc5b["ReplayingDecoder()"]
  acf0308a_b3b3_8956_f20c_c96385b17313 -->|method| 37e4c011_229f_2a4c_6ccd_33f12266cc5b
  269d1be6_3bb8_27dd_4d77_4a89ee02cca4["checkpoint()"]
  acf0308a_b3b3_8956_f20c_c96385b17313 -->|method| 269d1be6_3bb8_27dd_4d77_4a89ee02cca4
  c3f3f97d_7090_2707_525a_0b3212b62a34["S()"]
  acf0308a_b3b3_8956_f20c_c96385b17313 -->|method| c3f3f97d_7090_2707_525a_0b3212b62a34
  b8aef1bf_3001_84ff_42a1_fff6ca05d0a5["channelInputClosed()"]
  acf0308a_b3b3_8956_f20c_c96385b17313 -->|method| b8aef1bf_3001_84ff_42a1_fff6ca05d0a5
  7a42f676_96b8_04a7_cf0b_eebac0c66323["callDecode()"]
  acf0308a_b3b3_8956_f20c_c96385b17313 -->|method| 7a42f676_96b8_04a7_cf0b_eebac0c66323

Relationship Graph

Source Code

codec-base/src/main/java/io/netty/handler/codec/ReplayingDecoder.java lines 268–424

public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {

    static final Signal REPLAY = Signal.valueOf(ReplayingDecoder.class, "REPLAY");

    private final ReplayingDecoderByteBuf replayable = new ReplayingDecoderByteBuf();
    private S state;
    private int checkpoint = -1;

    /**
     * Creates a new instance with no initial state (i.e: {@code null}).
     */
    protected ReplayingDecoder() {
        this(null);
    }

    /**
     * Creates a new instance with the specified initial state.
     */
    protected ReplayingDecoder(S initialState) {
        state = initialState;
    }

    /**
     * Stores the internal cumulative buffer's reader position.
     */
    protected void checkpoint() {
        checkpoint = internalBuffer().readerIndex();
    }

    /**
     * Stores the internal cumulative buffer's reader position and updates
     * the current decoder state.
     */
    protected void checkpoint(S state) {
        checkpoint();
        state(state);
    }

    /**
     * Returns the current state of this decoder.
     * @return the current state of this decoder
     */
    protected S state() {
        return state;
    }

    /**
     * Sets the current state of this decoder.
     * @return the old state of this decoder
     */
    protected S state(S newState) {
        S oldState = state;
        state = newState;
        return oldState;
    }

    @Override
    final void channelInputClosed(ChannelHandlerContext ctx, List<Object> out) throws Exception {
        try {
            replayable.terminate();
            if (cumulation != null) {
                callDecode(ctx, internalBuffer(), out);
            } else {
                replayable.setCumulation(Unpooled.EMPTY_BUFFER);
            }
            decodeLast(ctx, replayable, out);
        } catch (Signal replay) {
            // Ignore
            replay.expect(REPLAY);
        }
    }

    @Override
    protected void callDecode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
        replayable.setCumulation(in);
        try {
            while (in.isReadable()) {
                int oldReaderIndex = checkpoint = in.readerIndex();
                int outSize = out.size();

                if (outSize > 0) {

Frequently Asked Questions

What is the ReplayingDecoder class?
ReplayingDecoder is a class in the netty codebase, defined in codec-base/src/main/java/io/netty/handler/codec/ReplayingDecoder.java.
Where is ReplayingDecoder defined?
ReplayingDecoder is defined in codec-base/src/main/java/io/netty/handler/codec/ReplayingDecoder.java at line 268.

Analyze Your Own Codebase

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

Try Supermodel Free