public final class ProtoReader
- Object
- ProtoReader
Low-level protobuf wire-format reader used by generated
ProtoCodec implementations. Wraps a byte[] so the reader
can remaining() and slice nested-message bodies without
re-buffering.
Generated codecs call readTag() in a loop, dispatch on the
field number, and call the appropriate readXxx method. Unknown
fields are passed to skipField(int) – the same recovery
behaviour protoc-generated code exhibits.
Nested types
interface ProtoReader.PackedReader | Strategy hook for readPacked. |
Constructors
public ProtoReader(byte[] data) | |
public ProtoReader(byte[] data, int offset, int length) |
Methods
Inherited methods
Constructor details
ProtoReader
public ProtoReader(byte[] data)ProtoReader
public ProtoReader(byte[] data, int offset, int length)Method details
isAtEnd
public boolean isAtEnd()remaining
public int remaining()readTag
public int readTag()
throws IOExceptionReads the next tag (
(fieldNumber << 3) | wireType) or
returns 0 when the stream is at EOF. Generated codecs use
the 0 sentinel as the loop exit condition.Throws
skipField
public void skipField(int tag)
throws IOExceptionSkips a single field whose tag has already been consumed.
Wire type extracted from
tag (tag & 0x7).Throws
readVarint32
public int readVarint32()
throws IOExceptionThrows
readVarint64
public long readVarint64()
throws IOExceptionThrows
readFixed32
public int readFixed32()
throws IOExceptionThrows
readFixed64
public long readFixed64()
throws IOExceptionThrows
readFloat
public float readFloat()
throws IOExceptionThrows
readDouble
public double readDouble()
throws IOExceptionThrows
readBool
public boolean readBool()
throws IOExceptionThrows
zagZig32
public static int zagZig32(int n)zagZig64
public static long zagZig64(long n)readSInt32
public int readSInt32()
throws IOExceptionThrows
readSInt64
public long readSInt64()
throws IOExceptionThrows
readString
public String readString()
throws IOExceptionThrows
readBytes
public byte[] readBytes()
throws IOExceptionThrows
readMessage
public <T> T readMessage(ProtoCodec<T> codec)
throws IOExceptionReads a length-delimited sub-message via
codec.Throws
readPacked
public <T> void readPacked(List<T> target, ProtoReader.PackedReader<T> strategy)
throws IOExceptionReads a packed
repeated scalar segment and appends each
element to target using the supplied PackedReader strategy.Throws
of
public static ProtoReader of(byte[] data)Wraps the supplied byte array in a fresh reader. Convenience
for unit tests; production code allocates the reader directly.
drain
public static byte[] drain(ByteArrayInputStream in)
throws IOExceptionConvenience helper for callers that prefer
ByteArrayInputStream
over byte arrays. Not used internally but kept for symmetry
with ProtoWriter.stream().