ProtoReader

open class ProtoReader(source: BufferedSource)

Reads and decodes protocol message fields.

Constructors

Link copied to clipboard
constructor(source: BufferedSource)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open 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
open fun beginMessage(): Long

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
open fun endMessageAndGetUnknownFields(token: Long): 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 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

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

Link copied to clipboard
open 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
open 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
open fun readFixed32(): Int

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

Link copied to clipboard
open fun readFixed64(): Long

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

Link copied to clipboard
open fun readString(): String

Reads a string field value from the stream.

Link copied to clipboard
open 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
open fun readVarint32(): Int

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

Link copied to clipboard
open fun readVarint64(): Long

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

Link copied to clipboard
open fun skip()

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