Class ProtonDecoderState
java.lang.Object
org.apache.qpid.protonj2.codec.decoders.ProtonDecoderState
- All Implemented Interfaces:
DecoderState
State object used by the Built in Decoder implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default maximum depth the decoder will allow before triggering anDecodeExceptionwhen the state depth value is increased during a decode process of complex types that can next objects.static final intThe 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. -
Constructor Summary
ConstructorsConstructorDescriptionProtonDecoderState(ProtonDecoder decoder) Create a newDecoderStateinstance that is joined forever to the givenDecoder. -
Method Summary
Modifier and TypeMethodDescriptiondecodeUTF8(ProtonBuffer buffer, int length) Given a set of UTF-8 encoded bytes decode and return the String that represents that UTF-8 value.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.intGets the configured maximum depth that nested types such as Lists, Maps and Arrays can have before aDecodeExceptionis thrown.intGets the configured maximum number of elements that can be decoded from an array encoded with the zero width AMQP types (Null, UInt0.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.reset()Resets any intermediate state back to default values.setDepthLimit(int limit) Sets the configured maximum depth that nested types such as Lists, Maps and Arrays can have before aDecodeExceptionis 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.setMaxZeroWidthArrayElements(int maxElements) Sets the configured maximum number of elements that can be decoded from an array encoded with the zero width AMQP types (Null, UInt0.setStringDecoder(UTF8Decoder stringDecoder) Sets a custom UTF-8Stringdecoder that will be used for allStringdecoding done from the encoder associated with thisDecoderStateinstance.
-
Field Details
-
DEFAULT_MAX_DECODE_DEPTH
public static final int DEFAULT_MAX_DECODE_DEPTHThe default maximum depth the decoder will allow before triggering anDecodeExceptionwhen 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_ELEMENTSThe 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
Create a newDecoderStateinstance that is joined forever to the givenDecoder.- Parameters:
decoder- TheDecoderthat this state instance is assigned to.
-
-
Method Details
-
getDecoder
- Specified by:
getDecoderin interfaceDecoderState- Returns:
- the decoder that created this state object
-
reset
Description copied from interface:DecoderStateResets any intermediate state back to default values.- Specified by:
resetin interfaceDecoderState- Returns:
- this
DecoderStateinstance.
-
getStringDecoder
- Returns:
- the currently set custom UTF-8
Stringdecoder or null if non set.
-
setStringDecoder
Sets a custom UTF-8Stringdecoder that will be used for allStringdecoding done from the encoder associated with thisDecoderStateinstance. If no decoder is registered then the implementation uses its own decoding algorithm.- Parameters:
stringDecoder- a customUTF8Decoderthat will be used for allStringdecoding.- Returns:
- this
Decoderinstance.
-
getMaxZeroWidthArrayElements
public int getMaxZeroWidthArrayElements()Description copied from interface:DecoderStateGets 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:
getMaxZeroWidthArrayElementsin interfaceDecoderState- Returns:
- the configured max number of zero width array encoding elements.
-
setMaxZeroWidthArrayElements
Description copied from interface:DecoderStateSets 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:
setMaxZeroWidthArrayElementsin interfaceDecoderState- Parameters:
maxElements- The configured max elements allowed in arrays encoded for zero width types.- Returns:
- this
DecoderStateinstance for chaining.
-
setDepthLimit
Description copied from interface:DecoderStateSets the configured maximum depth that nested types such as Lists, Maps and Arrays can have before aDecodeExceptionis 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:
setDepthLimitin interfaceDecoderState- Parameters:
limit- The configured limit on decoding types with nested element structures.
-
getDepthLimit
public int getDepthLimit()Description copied from interface:DecoderStateGets the configured maximum depth that nested types such as Lists, Maps and Arrays can have before aDecodeExceptionis thrown.- Specified by:
getDepthLimitin interfaceDecoderState- Returns:
- the configured maximum depth of nested types.
-
increaseDepth
Description copied from interface:DecoderStateDuring 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 anDecodeExceptionif that depth value is reached.- Specified by:
increaseDepthin interfaceDecoderState- Returns:
- this
DecoderStateinstance for chaining. - Throws:
DecodeException- if a set decoding depth limit is exceeded.
-
decreaseDepth
Description copied from interface:DecoderStateCalled 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:
decreaseDepthin interfaceDecoderState- Returns:
- this
DecoderStateinstance for chaining.
-
decodeUTF8
Description copied from interface:DecoderStateGiven a set of UTF-8 encoded bytes decode and return the String that represents that UTF-8 value.- Specified by:
decodeUTF8in interfaceDecoderState- 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.
-