ReverseProtoWriter

Encodes protocol buffer message fields from back-to-front for efficiency. Callers should write data in the opposite order that the data will be read.

One significant benefit of writing messages in reverse order is that length prefixes can be computed in constant time. Get the length of a message by subtracting the byteCount before writing it from byteCount after writing it.

Utilities for encoding and writing protocol message fields.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The total number of bytes emitted thus far.

Functions

Link copied to clipboard
fun writeBytes(value: ByteString)
Link copied to clipboard
fun writeFixed32(value: Int)

Write a little-endian 32-bit integer.

Link copied to clipboard
fun writeFixed64(value: Long)

Write a little-endian 64-bit integer.

Link copied to clipboard
fun writeString(value: String)
Link copied to clipboard
fun writeTag(fieldNumber: Int, fieldEncoding: FieldEncoding)

Encode and write a tag.

Link copied to clipboard
fun writeTo(sink: BufferedSink)
Link copied to clipboard
fun writeVarint32(value: Int)

Encode and write a varint. value is treated as unsigned, so it won't be sign-extended if negative.

Link copied to clipboard
fun writeVarint64(value: Long)

Encode and write a varint.