Varint21LengthFieldPrepender.java
net.minecraft.network.Varint21LengthFieldPrepender
信息
- 全限定名:net.minecraft.network.Varint21LengthFieldPrepender
- 类型:public class
- 包:net.minecraft.network
- 源码路径:src/main/java/net/minecraft/network/Varint21LengthFieldPrepender.java
- 起始行号:L10
- 继承:MessageToByteEncoder
- 职责:
TODO
字段/常量
MAX_VARINT21_BYTES- 类型:
int - 修饰符:
public static final - 源码定位:
L11 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) @ L13
- 方法名:encode
- 源码定位:L13
- 返回类型:void
- 修饰符:protected
参数:
- ctx: ChannelHandlerContext
- msg: ByteBuf
- out: ByteBuf
说明:
TODO
代码
@Sharable
public class Varint21LengthFieldPrepender extends MessageToByteEncoder<ByteBuf> {
public static final int MAX_VARINT21_BYTES = 3;
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) {
int bodyLength = msg.readableBytes();
int headerLength = VarInt.getByteSize(bodyLength);
if (headerLength > 3) {
throw new EncoderException("Packet too large: size " + bodyLength + " is over 8");
} else {
out.ensureWritable(headerLength + bodyLength);
VarInt.write(out, bodyLength);
out.writeBytes(msg, msg.readerIndex(), bodyLength);
}
}
}引用的其他类
- VarInt
- 引用位置:
方法调用 - 关联成员:
VarInt.getByteSize(), VarInt.write()
- 引用位置: