ProtoReader32

interface ProtoReader32

Reads and decodes protocol message fields using an Int as a cursor.

This is an alternative to ProtoReader, which uses Long as a cursor. It originates as an optimization for Kotlin/JS, where Long cursors are prohibitively expensive. It doesn't subclass ProtoReader because nextTag and forEachTag must each return the appropriate cursor type.

Functions

Link copied to clipboard
abstract fun addUnknownField(tag: Int, fieldEncoding: FieldEncoding, value: Any?)

Store an already read field temporarily. Once the entire message is read, call endMessageAndGetUnknownFields to retrieve unknown fields.

Link copied to clipboard
abstract fun asProtoReader(): ProtoReader

Returns a ProtoReader that reads the same data as this using a different type.

Link copied to clipboard

Prepares to read a value and returns true if the read should proceed. If there's nothing to read (because a packed value has length 0), this will clear the reader state.

Link copied to clipboard
abstract fun beginMessage(): Int

Begin a nested message. A call to this method will restrict the reader so that nextTag returns -1 when the message is complete. An accompanying call to endMessage must then occur with the opaque token returned from this method.

Link copied to clipboard
abstract fun endMessageAndGetUnknownFields(token: Int): ByteString

End a length-delimited nested message. Calls to this method must be symmetric with calls to beginMessage.

Link copied to clipboard
@JvmName(name = "-forEachTag")
inline fun ProtoReader32.forEachTag(tagHandler: (Int) -> Any): ByteString

Reads each tag, handles it, and returns a byte string with the unknown fields.

Link copied to clipboard

Returns the min length of the next field in bytes. Some encodings have a fixed length, while others have a variable length. LENGTH_DELIMITED fields have a known variable length, while VARINT fields could be as small as a single byte.

Link copied to clipboard
abstract fun nextLengthDelimited(): Int

Reads and returns the length of the next message in a length-delimited stream.

Link copied to clipboard
abstract fun nextTag(): Int

Reads and returns the next tag of the message, or -1 if there are no further tags. Use peekFieldEncoding after calling this method to query its encoding. This silently skips groups.

Link copied to clipboard

Returns the encoding of the next field value. nextTag must be called before this method.

Link copied to clipboard
abstract fun readBytes(): ByteString

Reads a bytes field value from the stream. The length is read from the stream prior to the actual data.

Link copied to clipboard
abstract fun readFixed32(): Int

Reads a 32-bit little-endian integer from the stream.

Link copied to clipboard
abstract fun readFixed64(): Long

Reads a 64-bit little-endian integer from the stream.

Link copied to clipboard
abstract fun readString(): String

Reads a string field value from the stream.

Link copied to clipboard
abstract fun readUnknownField(tag: Int)

Read an unknown field and store temporarily. Once the entire message is read, call endMessageAndGetUnknownFields to retrieve unknown fields.

Link copied to clipboard
abstract fun readVarint32(): Int

Reads a raw varint from the stream. If larger than 32 bits, discard the upper bits.

Link copied to clipboard
abstract fun readVarint64(): Long

Reads a raw varint up to 64 bits in length from the stream.

Link copied to clipboard
abstract fun skip()

Skips the current field's value. This is only safe to call immediately following a call to nextTag.