Package io.micronaut.serde
Class LimitingStream
java.lang.Object
io.micronaut.serde.LimitingStream
- Direct Known Subclasses:
AbstractStreamDecoder
,BsonWriterEncoder
,JacksonDecoder
,JacksonEncoder
,JsonNodeDecoder
,JsonNodeEncoder
,OracleJdbcJsonGeneratorEncoder
Utility class to check data limits in encoders and decoders. Currently, the only limit that is
checked is the nesting depth.
This class can be used in both implementation "patterns" for Encoder
(and
Decoder
): For the same-object pattern, where Encoder.encodeObject(Argument)
returns the same instance, the encoder should call increaseDepth()
, with a
corresponding decreaseDepth()
call in Encoder.finishStructure()
. Conversely, if
the encoder is implemented using the child-object pattern, where
Encoder.encodeObject(Argument)
returns a child encoder responsible for the subtree, that
child encoder should be instantiated using the new limits returned by childLimits()
.
If there is a limit violation, childLimits()
or increaseDepth()
will throw an
exception.
- Since:
- 2.0.0
- Author:
- Jonas Konrad
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
This data structure contains the limits for this stream. -
Field Summary
Modifier and TypeFieldDescriptionstatic final LimitingStream.RemainingLimits
Default limits, only use this when noSerdeConfiguration
is available.static final int
Default nesting depth limit. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final @NonNull LimitingStream.RemainingLimits
Get the limits of a new child encoder.protected final void
Decrease the current depth, always needs a correspondingincreaseDepth()
call.protected final void
Increase the current depth.limitsFromConfiguration
(SerdeConfiguration configuration) Get the configured limits.protected final @NonNull LimitingStream.RemainingLimits
Get a snapshot of our current limits to be passed to the constructor.
-
Field Details
-
DEFAULT_MAXIMUM_DEPTH
public static final int DEFAULT_MAXIMUM_DEPTHDefault nesting depth limit.- See Also:
-
DEFAULT_LIMITS
Default limits, only use this when noSerdeConfiguration
is available.
-
-
Constructor Details
-
LimitingStream
-
-
Method Details
-
ourLimits
Get a snapshot of our current limits to be passed to the constructor. This can be used for buffering decoders, when a new decoder takes over but no change in depth takes place.- Returns:
- The current limits
-
childLimits
@NonNull protected final @NonNull LimitingStream.RemainingLimits childLimits() throws SerdeExceptionGet the limits of a new child encoder.- Returns:
- The new limits
- Throws:
SerdeException
- If there is a nesting depth limit violation
-
increaseDepth
Increase the current depth.- Throws:
SerdeException
- If there is a nesting depth limit violation
-
decreaseDepth
protected final void decreaseDepth()Decrease the current depth, always needs a correspondingincreaseDepth()
call. -
limitsFromConfiguration
public static LimitingStream.RemainingLimits limitsFromConfiguration(SerdeConfiguration configuration) Get the configured limits.- Parameters:
configuration
- The serde configuration- Returns:
- The configured limits
-