wire-runtime / com.squareup.wire / ProtoReader

ProtoReader

class ProtoReader

Reads and decodes protocol message fields.

Constructors

<init>

ProtoReader(source: BufferedSource)

Functions

beginMessage

fun beginMessage(): Long

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

endMessage

fun endMessage(token: Long): Unit

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

forEachTag

fun forEachTag(tagHandler: TagHandler): ByteString

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

nextTag

fun nextTag(): Int

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

peekFieldEncoding

fun peekFieldEncoding(): FieldEncoding

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

readBytes

fun readBytes(): ByteString

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

readFixed32

fun readFixed32(): Int

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

readFixed64

fun readFixed64(): Long

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

readString

fun readString(): String

Reads a string field value from the stream.

readVarint32

fun readVarint32(): Int

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

readVarint64

fun readVarint64(): Long

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

skip

fun skip(): Unit

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