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.

  • 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