ProtobufVarint32LengthFieldPrepender Class — netty Architecture
Architecture documentation for the ProtobufVarint32LengthFieldPrepender class in ProtobufVarint32LengthFieldPrepender.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD c802204f_c6f7_7dc6_7b18_0b760262838a["ProtobufVarint32LengthFieldPrepender"] 431fddbd_6c7b_49e3_819f_79c81766b79b["ProtobufVarint32LengthFieldPrepender.java"] c802204f_c6f7_7dc6_7b18_0b760262838a -->|defined in| 431fddbd_6c7b_49e3_819f_79c81766b79b 5d8c7240_0ee0_e27b_8f3e_6b35db03b8e2["ProtobufVarint32LengthFieldPrepender()"] c802204f_c6f7_7dc6_7b18_0b760262838a -->|method| 5d8c7240_0ee0_e27b_8f3e_6b35db03b8e2 ed001db2_9529_f359_c93b_c3e10aed6648["encode()"] c802204f_c6f7_7dc6_7b18_0b760262838a -->|method| ed001db2_9529_f359_c93b_c3e10aed6648 36032e25_3b9d_d43b_2b28_b7289870c8d7["writeRawVarint32()"] c802204f_c6f7_7dc6_7b18_0b760262838a -->|method| 36032e25_3b9d_d43b_2b28_b7289870c8d7 9714be53_8fbd_3ba3_4cd4_53e89932050b["computeRawVarint32Size()"] c802204f_c6f7_7dc6_7b18_0b760262838a -->|method| 9714be53_8fbd_3ba3_4cd4_53e89932050b
Relationship Graph
Source Code
codec-protobuf/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java lines 40–94
@Sharable
public class ProtobufVarint32LengthFieldPrepender extends MessageToByteEncoder<ByteBuf> {
public ProtobufVarint32LengthFieldPrepender() {
super(ByteBuf.class);
}
@Override
protected void encode(
ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
int bodyLen = msg.readableBytes();
int headerLen = computeRawVarint32Size(bodyLen);
out.ensureWritable(headerLen + bodyLen);
writeRawVarint32(out, bodyLen);
out.writeBytes(msg, msg.readerIndex(), bodyLen);
}
/**
* Writes protobuf varint32 to (@link ByteBuf).
* @param out to be written to
* @param value to be written
*/
static void writeRawVarint32(ByteBuf out, int value) {
while (true) {
if ((value & ~0x7F) == 0) {
out.writeByte(value);
return;
} else {
out.writeByte((value & 0x7F) | 0x80);
value >>>= 7;
}
}
}
/**
* Computes size of protobuf varint32 after encoding.
* @param value which is to be encoded.
* @return size of value encoded as protobuf varint32.
*/
static int computeRawVarint32Size(final int value) {
if ((value & (0xffffffff << 7)) == 0) {
return 1;
}
if ((value & (0xffffffff << 14)) == 0) {
return 2;
}
if ((value & (0xffffffff << 21)) == 0) {
return 3;
}
if ((value & (0xffffffff << 28)) == 0) {
return 4;
}
return 5;
}
}
Source
Frequently Asked Questions
What is the ProtobufVarint32LengthFieldPrepender class?
ProtobufVarint32LengthFieldPrepender is a class in the netty codebase, defined in codec-protobuf/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java.
Where is ProtobufVarint32LengthFieldPrepender defined?
ProtobufVarint32LengthFieldPrepender is defined in codec-protobuf/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java at line 40.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free