Class ProtonDecoderState

java.lang.Object
org.apache.qpid.protonj2.codec.decoders.ProtonDecoderState
All Implemented Interfaces:
DecoderState

public final class ProtonDecoderState extends Object implements DecoderState
State object used by the Built in Decoder implementation.
  • Field Details

    • DEFAULT_MAX_DECODE_DEPTH

      public static final int DEFAULT_MAX_DECODE_DEPTH
      The default maximum depth the decoder will allow before triggering an DecodeException when the state depth value is increased during a decode process of complex types that can next objects.
      See Also:
    • DEFAULT_MAX_ZERO_WIDTH_ARRAY_ELEMENTS

      public static final int DEFAULT_MAX_ZERO_WIDTH_ARRAY_ELEMENTS
      The default maximum number of zero width array elements that controls the size of an zero width array type that can be decoded without throwing an DecodeException.
      See Also:
  • Constructor Details

    • ProtonDecoderState

      public ProtonDecoderState(ProtonDecoder decoder)
      Create a new DecoderState instance that is joined forever to the given Decoder.
      Parameters:
      decoder - The Decoder that this state instance is assigned to.
  • Method Details

    • getDecoder

      public ProtonDecoder getDecoder()
      Specified by:
      getDecoder in interface DecoderState
      Returns:
      the decoder that created this state object
    • reset

      public ProtonDecoderState reset()
      Description copied from interface: DecoderState
      Resets any intermediate state back to default values.
      Specified by:
      reset in interface DecoderState
      Returns:
      this DecoderState instance.
    • getStringDecoder

      public UTF8Decoder getStringDecoder()
      Returns:
      the currently set custom UTF-8 String decoder or null if non set.
    • setStringDecoder

      public ProtonDecoderState setStringDecoder(UTF8Decoder stringDecoder)
      Sets a custom UTF-8 String decoder that will be used for all String decoding done from the encoder associated with this DecoderState instance. If no decoder is registered then the implementation uses its own decoding algorithm.
      Parameters:
      stringDecoder - a custom UTF8Decoder that will be used for all String decoding.
      Returns:
      this Decoder instance.
    • getMaxZeroWidthArrayElements

      public int getMaxZeroWidthArrayElements()
      Description copied from interface: DecoderState
      Gets the configured maximum number of elements that can be decoded from an array encoded with the zero width AMQP types (Null, UInt0. ULong0, List0, Boolean_False and Boolean_True). A return value of zero indicates that the decoder should allow any zero sized arrays of zero width types and throw for all others (the new default).
      Specified by:
      getMaxZeroWidthArrayElements in interface DecoderState
      Returns:
      the configured max number of zero width array encoding elements.
    • setMaxZeroWidthArrayElements

      public ProtonDecoderState setMaxZeroWidthArrayElements(int maxElements)
      Description copied from interface: DecoderState
      Sets the configured maximum number of elements that can be decoded from an array encoded with the zero width AMQP types (Null, UInt0. ULong0, List0, Boolean_False and Boolean_True). These are uncommon encodings and can lead to small encodings with large memory costs at decode which makes them discouraged for normal use.

      It is recommended that for implementations that implement this limit configuration the default be zero meaning zero width array encodings are disabled and will always throw a DecodeException

      Specified by:
      setMaxZeroWidthArrayElements in interface DecoderState
      Parameters:
      maxElements - The configured max elements allowed in arrays encoded for zero width types.
      Returns:
      this DecoderState instance for chaining.
    • setDepthLimit

      public ProtonDecoderState setDepthLimit(int limit)
      Description copied from interface: DecoderState
      Sets the configured maximum depth that nested types such as Lists, Maps and Arrays can have before a DecodeException is thrown to allow the decoder to error in cases where the depth of encoding exceeds what the environment is thought to be able to support.
      Specified by:
      setDepthLimit in interface DecoderState
      Parameters:
      limit - The configured limit on decoding types with nested element structures.
    • getDepthLimit

      public int getDepthLimit()
      Description copied from interface: DecoderState
      Gets the configured maximum depth that nested types such as Lists, Maps and Arrays can have before a DecodeException is thrown.
      Specified by:
      getDepthLimit in interface DecoderState
      Returns:
      the configured maximum depth of nested types.
    • increaseDepth

      public ProtonDecoderState increaseDepth() throws DecodeException
      Description copied from interface: DecoderState
      During decode of AMQP types which can be comprised of a nesting of other AMQP types the such as Lists, Maps and Arrays, the depth is increased to track the amount of type nesting that comprises the type being decoded. Implementations can use this value to impose limits on the depth of nested objects within complex types and throw an DecodeException if that depth value is reached.
      Specified by:
      increaseDepth in interface DecoderState
      Returns:
      this DecoderState instance for chaining.
      Throws:
      DecodeException - if a set decoding depth limit is exceeded.
    • decreaseDepth

      public ProtonDecoderState decreaseDepth()
      Description copied from interface: DecoderState
      Called once decoding of one level of a nested type completes to reduce to the previous level before proceeding to the next element on the current level if any.
      Specified by:
      decreaseDepth in interface DecoderState
      Returns:
      this DecoderState instance for chaining.
    • decodeUTF8

      public String decodeUTF8(ProtonBuffer buffer, int length) throws DecodeException
      Description copied from interface: DecoderState
      Given a set of UTF-8 encoded bytes decode and return the String that represents that UTF-8 value.
      Specified by:
      decodeUTF8 in interface DecoderState
      Parameters:
      buffer - A buffer containing the UTF-8 encoded bytes to be decoded.
      length - The number of bytes in the passed buffer that comprise the UTF-8 encoding.
      Returns:
      a String that represents the UTF-8 decoded bytes.
      Throws:
      DecodeException - if an error occurs while decoding the string value.