# Class ProtoReader

java.lang.Object
com.codename1.io.grpc.ProtoReader

public final class ProtoReader extends Object

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 Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `ProtoReader.PackedReader<T>`
  Strategy hook for `readPacked(List, ProtoReader.PackedReader)`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ProtoReader(byte[] data)`
  `ProtoReader(byte[] data, int offset, int length)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static byte[]`
  `drain(ByteArrayInputStream in)`
  Convenience helper for callers that prefer `ByteArrayInputStream` over byte arrays.
  `boolean`
  `isAtEnd()`
  `static ProtoReader`
  `of(byte[] data)`
  Wraps the supplied byte array in a fresh reader.
  `boolean`
  `readBool()`
  `byte[]`
  `readBytes()`
  `double`
  `readDouble()`
  `int`
  `readFixed32()`
  `long`
  `readFixed64()`
  `float`
  `readFloat()`
  `<T> T`
  `readMessage(ProtoCodec<T> codec)`
  Reads a length-delimited sub-message via `codec`.
  `<T> void`
  `readPacked(List<T> target, ProtoReader.PackedReader<T> strategy)`
  Reads a packed `repeated` scalar segment and appends each element to `target` using the supplied `ProtoReader.PackedReader` strategy.
  `int`
  `readSInt32()`
  `long`
  `readSInt64()`
  `String`
  `readString()`
  `int`
  `readTag()`
  Reads the next tag (`(fieldNumber << 3) | wireType`) or returns 0 when the stream is at EOF.
  `int`
  `readVarint32()`
  `long`
  `readVarint64()`
  `int`
  `remaining()`
  `void`
  `skipField(int tag)`
  Skips a single field whose tag has already been consumed.
  `static int`
  `zagZig32(int n)`
  `static long`
  `zagZig64(long n)`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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.
    Throws:
      `IOException`

  - ### 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`).
    Throws:
      `IOException`

  - ### readVarint32

    public int readVarint32() throws IOException
    Throws:
      `IOException`

  - ### readVarint64

    public long readVarint64() throws IOException
    Throws:
      `IOException`

  - ### readFixed32

    public int readFixed32() throws IOException
    Throws:
      `IOException`

  - ### readFixed64

    public long readFixed64() throws IOException
    Throws:
      `IOException`

  - ### readFloat

    public float readFloat() throws IOException
    Throws:
      `IOException`

  - ### readDouble

    public double readDouble() throws IOException
    Throws:
      `IOException`

  - ### readBool

    public boolean readBool() throws IOException
    Throws:
      `IOException`

  - ### zagZig32

    public static int zagZig32(int n)

  - ### zagZig64

    public static long zagZig64(long n)

  - ### readSInt32

    public int readSInt32() throws IOException
    Throws:
      `IOException`

  - ### readSInt64

    public long readSInt64() throws IOException
    Throws:
      `IOException`

  - ### readString

    public String readString() throws IOException
    Throws:
      `IOException`

  - ### readBytes

    public byte[] readBytes() throws IOException
    Throws:
      `IOException`

  - ### readMessage

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

  - ### 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 `ProtoReader.PackedReader` strategy.
    Throws:
      `IOException`

  - ### 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()`.
    Throws:
      `IOException`