Class ProtoReader
java.lang.Object
com.codename1.io.grpc.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 Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceStrategy hook forreadPacked(List, ProtoReader.PackedReader). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Convenience helper for callers that preferByteArrayInputStreamover byte arrays.booleanisAtEnd()static ProtoReaderof(byte[] data) Wraps the supplied byte array in a fresh reader.booleanreadBool()byte[]doubleintlongfloat<T> TreadMessage(ProtoCodec<T> codec) Reads a length-delimited sub-message viacodec.<T> voidreadPacked(List<T> target, ProtoReader.PackedReader<T> strategy) Reads a packedrepeatedscalar segment and appends each element totargetusing the suppliedProtoReader.PackedReaderstrategy.intlongintreadTag()Reads the next tag ((fieldNumber << 3) | wireType) or returns 0 when the stream is at EOF.intlongintvoidskipField(int tag) Skips a single field whose tag has already been consumed.static intzagZig32(int n) static longzagZig64(long n)
-
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
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
Skips a single field whose tag has already been consumed. Wire type extracted fromtag(tag & 0x7).- Throws:
IOException
-
readVarint32
- Throws:
IOException
-
readVarint64
- Throws:
IOException
-
readFixed32
- Throws:
IOException
-
readFixed64
- Throws:
IOException
-
readFloat
- Throws:
IOException
-
readDouble
- Throws:
IOException
-
readBool
- Throws:
IOException
-
zagZig32
public static int zagZig32(int n) -
zagZig64
public static long zagZig64(long n) -
readSInt32
- Throws:
IOException
-
readSInt64
- Throws:
IOException
-
readString
- Throws:
IOException
-
readBytes
- Throws:
IOException
-
readMessage
Reads a length-delimited sub-message viacodec.- Throws:
IOException
-
readPacked
Reads a packedrepeatedscalar segment and appends each element totargetusing the suppliedProtoReader.PackedReaderstrategy.- Throws:
IOException
-
of
Wraps the supplied byte array in a fresh reader. Convenience for unit tests; production code allocates the reader directly. -
drain
Convenience helper for callers that preferByteArrayInputStreamover byte arrays. Not used internally but kept for symmetry withProtoWriter.stream().- Throws:
IOException
-