# Class ProtoReader

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

public final class ProtoReader extends java.lang.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(java.io.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 java.lang.Object

  `clone, equals, finalize, 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 java.io.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:
      `java.io.IOException`

  - ### skipField

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

  - ### readVarint32

    public int readVarint32() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### readVarint64

    public long readVarint64() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### readFixed32

    public int readFixed32() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### readFixed64

    public long readFixed64() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### readFloat

    public float readFloat() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### readDouble

    public double readDouble() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### readBool

    public boolean readBool() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### zagZig32

    public static int zagZig32(int n)

  - ### zagZig64

    public static long zagZig64(long n)

  - ### readSInt32

    public int readSInt32() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### readSInt64

    public long readSInt64() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### readString

    public String readString() throws java.io.IOException
    Throws:
      `java.io.IOException`

  - ### readBytes

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

  - ### readMessage

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

  - ### readPacked

    public <T> void readPacked(List<T> target, ProtoReader.PackedReader<T> strategy) throws java.io.IOException
    Reads a packed `repeated` scalar segment and appends each element to `target` using the supplied `ProtoReader.PackedReader` strategy.
    Throws:
      `java.io.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(java.io.ByteArrayInputStream in) throws java.io.IOException
    Convenience helper for callers that prefer `ByteArrayInputStream` over byte arrays. Not used internally but kept for symmetry with `ProtoWriter.stream()`.
    Throws:
      `java.io.IOException`