public final class ProtoReader

  1. Object
  2. 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.PackedReaderStrategy hook for readPacked.

Constructors

public ProtoReader(byte[] data)
public ProtoReader(byte[] data, int offset, int length)

Methods

public boolean isAtEnd()
public int remaining()
public int readTag() throws IOExceptionReads the next tag ((fieldNumber << 3) | wireType) or returns 0 when the stream is at EOF.
public void skipField(int tag) throws IOExceptionSkips a single field whose tag has already been consumed.
public int readVarint32() throws IOException
public long readVarint64() throws IOException
public int readFixed32() throws IOException
public long readFixed64() throws IOException
public float readFloat() throws IOException
public double readDouble() throws IOException
public boolean readBool() throws IOException
public static int zagZig32(int n)
public static long zagZig64(long n)
public int readSInt32() throws IOException
public long readSInt64() throws IOException
public String readString() throws IOException
public byte[] readBytes() throws IOException
public <T> T readMessage(ProtoCodec<T> codec) throws IOExceptionReads a length-delimited sub-message via codec.
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.
public static ProtoReader of(byte[] data)Wraps the supplied byte array in a fresh reader.
public static byte[] drain(ByteArrayInputStream in) throws IOExceptionConvenience helper for callers that prefer ByteArrayInputStream over byte arrays.

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 IOException
Reads 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.

skipField

public void skipField(int tag) throws IOException
Skips a single field whose tag has already been consumed. Wire type extracted from tag (tag & 0x7).

readVarint32

public int readVarint32() throws IOException

readVarint64

public long readVarint64() throws IOException

readFixed32

public int readFixed32() throws IOException

readFixed64

public long readFixed64() throws IOException

readFloat

public float readFloat() throws IOException

readDouble

public double readDouble() throws IOException

readBool

public boolean readBool() throws IOException

zagZig32

public static int zagZig32(int n)

zagZig64

public static long zagZig64(long n)

readSInt32

public int readSInt32() throws IOException

readSInt64

public long readSInt64() throws IOException

readString

public String readString() throws IOException

readBytes

public byte[] readBytes() throws IOException

readMessage

public <T> T readMessage(ProtoCodec<T> codec) throws IOException
Reads a length-delimited sub-message via codec.

readPacked

public <T> void readPacked(List<T> target, ProtoReader.PackedReader<T> strategy) throws IOException
Reads a packed repeated scalar segment and appends each element to target using the supplied PackedReader strategy.

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 IOException
Convenience helper for callers that prefer ByteArrayInputStream over byte arrays. Not used internally but kept for symmetry with ProtoWriter.stream().