NbtAccounter.java
net.minecraft.nbt.NbtAccounter
信息
- 全限定名:net.minecraft.nbt.NbtAccounter
- 类型:public class
- 包:net.minecraft.nbt
- 源码路径:src/main/java/net/minecraft/nbt/NbtAccounter.java
- 起始行号:L5
- 职责:
TODO
字段/常量
-
DEFAULT_NBT_QUOTA- 类型:
int - 修饰符:
public static final - 源码定位:
L6 - 说明:
TODO
- 类型:
-
UNCOMPRESSED_NBT_QUOTA- 类型:
int - 修饰符:
public static final - 源码定位:
L7 - 说明:
TODO
- 类型:
-
MAX_STACK_DEPTH- 类型:
int - 修饰符:
private static final - 源码定位:
L8 - 说明:
TODO
- 类型:
-
quota- 类型:
long - 修饰符:
private final - 源码定位:
L9 - 说明:
TODO
- 类型:
-
usage- 类型:
long - 修饰符:
private - 源码定位:
L10 - 说明:
TODO
- 类型:
-
maxDepth- 类型:
int - 修饰符:
private final - 源码定位:
L11 - 说明:
TODO
- 类型:
-
depth- 类型:
int - 修饰符:
private - 源码定位:
L12 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public NbtAccounter(long quota, int maxDepth) @ L14
- 构造器名:NbtAccounter
- 源码定位:L14
- 修饰符:public
参数:
- quota: long
- maxDepth: int
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static NbtAccounter create(long quota) @ L19
- 方法名:create
- 源码定位:L19
- 返回类型:NbtAccounter
- 修饰符:public static
参数:
- quota: long
说明:
TODO
public static NbtAccounter defaultQuota() @ L23
- 方法名:defaultQuota
- 源码定位:L23
- 返回类型:NbtAccounter
- 修饰符:public static
参数:
- 无
说明:
TODO
public static NbtAccounter uncompressedQuota() @ L27
- 方法名:uncompressedQuota
- 源码定位:L27
- 返回类型:NbtAccounter
- 修饰符:public static
参数:
- 无
说明:
TODO
public static NbtAccounter unlimitedHeap() @ L31
- 方法名:unlimitedHeap
- 源码定位:L31
- 返回类型:NbtAccounter
- 修饰符:public static
参数:
- 无
说明:
TODO
public void accountBytes(long bytesPerEntry, long count) @ L35
- 方法名:accountBytes
- 源码定位:L35
- 返回类型:void
- 修饰符:public
参数:
- bytesPerEntry: long
- count: long
说明:
TODO
public void accountBytes(long size) @ L39
- 方法名:accountBytes
- 源码定位:L39
- 返回类型:void
- 修饰符:public
参数:
- size: long
说明:
TODO
public void pushDepth() @ L51
- 方法名:pushDepth
- 源码定位:L51
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void popDepth() @ L59
- 方法名:popDepth
- 源码定位:L59
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public long getUsage() @ L67
- 方法名:getUsage
- 源码定位:L67
- 返回类型:long
- 修饰符:public
参数:
- 无
说明:
TODO
public int getDepth() @ L72
- 方法名:getDepth
- 源码定位:L72
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class NbtAccounter {
public static final int DEFAULT_NBT_QUOTA = 2097152;
public static final int UNCOMPRESSED_NBT_QUOTA = 104857600;
private static final int MAX_STACK_DEPTH = 512;
private final long quota;
private long usage;
private final int maxDepth;
private int depth;
public NbtAccounter(long quota, int maxDepth) {
this.quota = quota;
this.maxDepth = maxDepth;
}
public static NbtAccounter create(long quota) {
return new NbtAccounter(quota, 512);
}
public static NbtAccounter defaultQuota() {
return new NbtAccounter(2097152L, 512);
}
public static NbtAccounter uncompressedQuota() {
return new NbtAccounter(104857600L, 512);
}
public static NbtAccounter unlimitedHeap() {
return new NbtAccounter(Long.MAX_VALUE, 512);
}
public void accountBytes(long bytesPerEntry, long count) {
this.accountBytes(bytesPerEntry * count);
}
public void accountBytes(long size) {
if (size < 0L) {
throw new IllegalArgumentException("Tried to account NBT tag with negative size: " + size);
} else if (this.usage + size > this.quota) {
throw new NbtAccounterException(
"Tried to read NBT tag that was too big; tried to allocate: " + this.usage + " + " + size + " bytes where max allowed: " + this.quota
);
} else {
this.usage += size;
}
}
public void pushDepth() {
if (this.depth >= this.maxDepth) {
throw new NbtAccounterException("Tried to read NBT tag with too high complexity, depth > " + this.maxDepth);
} else {
this.depth++;
}
}
public void popDepth() {
if (this.depth <= 0) {
throw new NbtAccounterException("NBT-Accounter tried to pop stack-depth at top-level");
} else {
this.depth--;
}
}
@VisibleForTesting
public long getUsage() {
return this.usage;
}
@VisibleForTesting
public int getDepth() {
return this.depth;
}
}引用的其他类
- NbtAccounterException
- 引用位置:
构造调用 - 关联成员:
NbtAccounterException()
- 引用位置: