Class ProtonStreamDecoderState

java.lang.Object
org.apache.qpid.protonj2.codec.decoders.ProtonStreamDecoderState
All Implemented Interfaces:
StreamDecoderState

public final class ProtonStreamDecoderState extends Object implements StreamDecoderState
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

  • Method Details

    • getDecoder

      public ProtonStreamDecoder getDecoder()
      Specified by:
      getDecoder in interface StreamDecoderState
      Returns:
      the StreamDecoder that created this state object
    • reset

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

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

      public void setStringDecoder(UTF8StreamDecoder stringDecoder)
      Sets a custom UTF-8 String decoder that will be used for all String decoding done from the encoder associated with this StreamDecoderState 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.
    • getMaxZeroWidthArrayElements

      public int getMaxZeroWidthArrayElements()
      Description copied from interface: StreamDecoderState
      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 StreamDecoderState
      Returns:
      the configured max number of zero width array encoding elements.
    • setMaxZeroWidthArrayElements

      public ProtonStreamDecoderState setMaxZeroWidthArrayElements(int maxElements)
      Description copied from interface: StreamDecoderState
      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 StreamDecoderState
      Parameters:
      maxElements - The configured max elements allowed in arrays encoded for zero width types.
      Returns:
      this StreamDecoderState instance for chaining.
    • getMaxStringSize

      public int getMaxStringSize()
      Description copied from interface: StreamDecoderState
      Gets the configured maximum size of an encoded string this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      getMaxStringSize in interface StreamDecoderState
      Returns:
      the configured max encoded string size supported.
    • setMaxStringSize

      public ProtonStreamDecoderState setMaxStringSize(int maxStringLength)
      Description copied from interface: StreamDecoderState
      Sets the configured maximum size of an encoded string this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      setMaxStringSize in interface StreamDecoderState
      Parameters:
      maxStringLength - The maximum allowed encoded size value to allow before an decoding exception is thrown.
      Returns:
      this StreamDecoderState instance for chaining.
    • getMaxArraySize

      public int getMaxArraySize()
      Description copied from interface: StreamDecoderState
      Gets the configured maximum size of an encoded array this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      getMaxArraySize in interface StreamDecoderState
      Returns:
      the configured max encoded array size supported.
    • setMaxArraySize

      public ProtonStreamDecoderState setMaxArraySize(int maxArrayLength)
      Description copied from interface: StreamDecoderState
      Sets the configured maximum size of an encoded array this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      setMaxArraySize in interface StreamDecoderState
      Parameters:
      maxArrayLength - The maximum allowed encoded size value to allow before an decoding exception is thrown.
      Returns:
      this StreamDecoderState instance for chaining.
    • getMaxListSize

      public int getMaxListSize()
      Description copied from interface: StreamDecoderState
      Gets the configured maximum indicated encoded size of a List this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      getMaxListSize in interface StreamDecoderState
      Returns:
      the configured max encoded list elements supported.
    • setMaxListSize

      public ProtonStreamDecoderState setMaxListSize(int maxListSize)
      Description copied from interface: StreamDecoderState
      Sets the configured maximum indicated encoded size of a List this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      setMaxListSize in interface StreamDecoderState
      Parameters:
      maxListSize - The maximum allowed encoded size value to allow before an decoding exception is thrown.
      Returns:
      this StreamDecoderState instance for chaining.
    • getMaxMapSize

      public int getMaxMapSize()
      Description copied from interface: StreamDecoderState
      Gets the configured maximum indicated encoded size of a List this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      getMaxMapSize in interface StreamDecoderState
      Returns:
      the configured max encoded list size supported.
    • setMaxMapSize

      public ProtonStreamDecoderState setMaxMapSize(int maxMapSize)
      Description copied from interface: StreamDecoderState
      Sets the configured maximum indicated encoded size of a Map this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      setMaxMapSize in interface StreamDecoderState
      Parameters:
      maxMapSize - The maximum allowed encoded size value to allow before an decoding exception is thrown.
      Returns:
      this StreamDecoderState instance for chaining.
    • getMaxBinarySize

      public int getMaxBinarySize()
      Description copied from interface: StreamDecoderState
      Gets the configured maximum length of an encoded Binary this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      getMaxBinarySize in interface StreamDecoderState
      Returns:
      the configured max encoded binary length supported.
    • setMaxBinarySize

      public ProtonStreamDecoderState setMaxBinarySize(int maxBinaryLength)
      Description copied from interface: StreamDecoderState
      Gets the configured maximum size of an encoded Binary this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      setMaxBinarySize in interface StreamDecoderState
      Parameters:
      maxBinaryLength - The maximum allowed encoded size value to allow before an decoding exception is thrown.
      Returns:
      this StreamDecoderState instance for chaining.
    • getMaxSymbolSize

      public int getMaxSymbolSize()
      Description copied from interface: StreamDecoderState
      Gets the configured maximum size of an encoded Symbol this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      getMaxSymbolSize in interface StreamDecoderState
      Returns:
      the configured max encoded Symbol length supported.
    • setMaxSymbolSize

      public ProtonStreamDecoderState setMaxSymbolSize(int maxSymbolLength)
      Description copied from interface: StreamDecoderState
      Gets the configured maximum length of an encoded Symbol this decoder will allow before it throws an DecodeException to indicate that a rule violation has occurred.
      Specified by:
      setMaxSymbolSize in interface StreamDecoderState
      Parameters:
      maxSymbolLength - The maximum allowed encoded size value to allow before an decoding exception is thrown.
      Returns:
      this StreamDecoderState instance for chaining.
    • setDepthLimit

      public ProtonStreamDecoderState setDepthLimit(int limit)
      Description copied from interface: StreamDecoderState
      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 errors in cases where the depth of encoding exceeds that the environment can support.
      Specified by:
      setDepthLimit in interface StreamDecoderState
      Parameters:
      limit - The configured limit on decoding types with nested element structures.
      Returns:
      this StreamDecoderState instance for chaining.
    • getDepthLimit

      public int getDepthLimit()
      Description copied from interface: StreamDecoderState
      Gets 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 errors in cases where the depth of encoding exceeds that the environment can support.
      Specified by:
      getDepthLimit in interface StreamDecoderState
      Returns:
      the configured maximum depth of nested types.
    • increaseDepth

      public ProtonStreamDecoderState increaseDepth() throws DecodeException
      Description copied from interface: StreamDecoderState
      During decode of AMQP types which can be comprised of a nesting of other AMQP types 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 exceeded.
      Specified by:
      increaseDepth in interface StreamDecoderState
      Returns:
      this StreamDecoderState instance for chaining.
      Throws:
      DecodeException - if a set decoding depth limit is exceeded.
    • decreaseDepth

      public ProtonStreamDecoderState decreaseDepth()
      Description copied from interface: StreamDecoderState
      During decode as on level of complex type decode completes the level value is decreased
      Specified by:
      decreaseDepth in interface StreamDecoderState
      Returns:
      this StreamDecoderState instance for chaining.
    • decodeUTF8

      public String decodeUTF8(InputStream stream, int length) throws DecodeException
      Description copied from interface: StreamDecoderState
      Given a stream that will provide UTF-8 encoded bytes, decode and return the String that represents that UTF-8 value.
      Specified by:
      decodeUTF8 in interface StreamDecoderState
      Parameters:
      stream - A stream from which the UTF-8 encoded bytes are to be decoded.
      length - The number of bytes in the passed InputStream 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.