code: public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out)
              throws Exception {
          DecodingState state = getCurrentState();
  
          final int limit = in.limit();
          int pos = in.position();
  
          try {
              for (;;) {
                  // Wait for more data if all data is consumed.
                  if (pos == limit) {
                      break;
                  }
  
                  DecodingState oldState = state;
                  state = state.decode(in, childOutput);
  
                  // If finished, call finishDecode
                  if (state == null) {
                      return finishDecode(childProducts, out);
                  }
  
                  int newPos = in.position();
  
                  // Wait for more data if nothing is consumed and state didn't change.
                  if (newPos == pos && oldState == state) {
                      break;
                  }
                  pos = newPos;
              }
  
              return this;
          } catch (Exception e) {
              state = null;
              throw e;
          } finally {
              this.currentState = state;
  
              // Destroy if decoding is finished or failed.
              if (state == null) {
                  cleanup();
              }
          }
      }
docs: {@inheritDoc}