Package com.viaversion.nbt.limiter
Interface TagLimiter
public interface TagLimiter
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionintbytes()Returns the amount of currently read bytes.voidcheckLevel(int nestedLevel) Checks the current level of nesting and throws an exception if it exceeds the max levels.default voidvoidcountBytes(int bytes) Counts the given number of bytes and throws an exception if the max bytes count is exceeded.default voiddefault voiddefault voidcountInt()default voiddefault voidvoidcountTag()Counts a single created tag and throws an exception if the max tag count is exceeded.static TagLimitercreate(int maxBytes, int maxLevels) Returns a new tag limiter with the given max bytes, nesting levels and the default max tag count.static TagLimitercreate(int maxBytes, int maxLevels, int maxTags) Returns a new tag limiter with the given max bytes, nesting levels and tag count.intmaxBytes()Returns the max number of bytes to be read before an exception is thrown when reading nbt.intReturns the max number of levels of nesting before an exception is thrown when reading nbt.intmaxTags()Returns the max number of tags to be created before an exception is thrown when reading nbt.static TagLimiternoop()Returns a noop tag limiter.voidreset()Resets the current byte and tag counts.inttags()Returns the number of tags created so far.
-
Field Details
-
DEFAULT_MAX_BYTES
static final int DEFAULT_MAX_BYTES- See Also:
-
DEFAULT_MAX_NESTING_LEVEL
static final int DEFAULT_MAX_NESTING_LEVEL- See Also:
-
DEFAULT_MAX_TAGS
static final int DEFAULT_MAX_TAGS- See Also:
-
-
Method Details
-
create
Returns a new tag limiter with the given max bytes, nesting levels and the default max tag count.- Parameters:
maxBytes- max amount of bytes to be read before an exception is thrown when reading nbtmaxLevels- max levels of nesting before an exception is thrown when reading nbt- Returns:
- tag limiter
- See Also:
-
create
Returns a new tag limiter with the given max bytes, nesting levels and tag count.- Parameters:
maxBytes- max amount of bytes to be read before an exception is thrown when reading nbtmaxLevels- max levels of nesting before an exception is thrown when reading nbtmaxTags- max amount of tags to be created before an exception is thrown when reading nbt- Returns:
- tag limiter
-
noop
Returns a noop tag limiter.- Returns:
- noop tag limiter
-
countBytes
void countBytes(int bytes) Counts the given number of bytes and throws an exception if the max bytes count is exceeded.- Parameters:
bytes- bytes to count- Throws:
IllegalArgumentException- if max bytes count is exceeded
-
countTag
void countTag()Counts a single created tag and throws an exception if the max tag count is exceeded.Called once per tag produced while reading, regardless of the tag's wire size, to bound the number of heap objects a single read can allocate.
- Throws:
IllegalArgumentException- if the max tag count is exceeded
-
checkLevel
void checkLevel(int nestedLevel) Checks the current level of nesting and throws an exception if it exceeds the max levels.- Parameters:
nestedLevel- current level of nesting- Throws:
IllegalArgumentException- if max level count is exceeded
-
countByte
default void countByte() -
countShort
default void countShort() -
countInt
default void countInt() -
countFloat
default void countFloat() -
countLong
default void countLong() -
countDouble
default void countDouble() -
maxBytes
int maxBytes()Returns the max number of bytes to be read before an exception is thrown when reading nbt.- Returns:
- max bytes
-
maxLevels
int maxLevels()Returns the max number of levels of nesting before an exception is thrown when reading nbt.- Returns:
- max nesting levels
-
maxTags
int maxTags()Returns the max number of tags to be created before an exception is thrown when reading nbt.- Returns:
- max tags
-
bytes
int bytes()Returns the amount of currently read bytes.- Returns:
- currently read bytes
-
tags
int tags()Returns the number of tags created so far.- Returns:
- currently created tag count
-
reset
void reset()Resets the current byte and tag counts.
-