Import std.data.protobuf
ProtoWriter
class
Public Class ProtoWriter
Writes protobuf's wire format: each field's tag, then its value. A message inside another goes between BeginLength and EndLength, which put its length before it.
Examples
Local writer = ProtoWriter()
writer.WriteTag(ProtoTag(1, WIRE_VARINT))
writer.WriteInt32(150)
writer.WriteTag(ProtoTag(2, WIRE_LENGTH))
writer.WriteString("hi")
Local bytes = writer.Finish()
Expect(bytes == [0x08, 0x96, 0x01, 0x12, 0x02, 0x68, 0x69] As UInt8[])std/data/protobuf.fb, line 101
-
A new ProtoWriter, with nothing written.
-
How many bytes it has written.
-
Writes a field's
tag, its number and its wire type, as a varint. -
An unsigned varint: 7 bits a byte, the lowest first, with the top bit set on every byte but the last.
-
An int32 as protobuf writes one: a negative
valueas an Int64's 64 bits, in 10 bytes. -
Writes an int64, as a varint.
-
Writes a uint32, as a varint.
-
Writes a uint64, as a varint.
-
A sint32, zigzagged, so a small negative number takes as few bytes as a small positive one: 0, -1, 1, -2 are 0, 1, 2, 3.
-
Writes a sint64, zigzagged, so a small negative number takes as few bytes as a small positive one.
-
Writes a bool, as a varint of 1 or 0.
-
4 bytes, the lowest first.
-
8 bytes, the lowest first.
-
Writes an sfixed32, as its 4 bytes, the lowest first.
-
Writes an sfixed64, as its 8 bytes, the lowest first.
-
A float's IEEE 754 bits, in 4 bytes.
-
A double's IEEE 754 bits, in 8 bytes.
-
Its length, then its bytes.
-
Its UTF-8's length, then its UTF-8.
-
Bytes as they are, like the fields a message didn't know, which it keeps.
-
Starts what a length goes before, like a message inside another or a packed field's values, and gives where, for EndLength.
-
Puts the length of what was written since BeginLength gave
startbefore it. Panics whenstartisn't where a BeginLength left room for a length. -
What it has written, after which it starts again, empty.
Report an issue with this page or with FutureBlitz on GitHub.