Skip to content
FutureBlitz

    Install

    Import std.data.protobuf

    ProtoWriter

    std.data.protobuf

    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

    • Public New() constructor #

      A new ProtoWriter, with nothing written.

    • Public Property Count: Int property #

      How many bytes it has written.

    • Public Method WriteTag(tag: UInt32) method #

      Writes a field's tag, its number and its wire type, as a varint.

    • Public Method WriteVarint(value: UInt64) method #

      An unsigned varint: 7 bits a byte, the lowest first, with the top bit set on every byte but the last.

    • Public Method WriteInt32(value: Int32) method #

      An int32 as protobuf writes one: a negative value as an Int64's 64 bits, in 10 bytes.

    • Public Method WriteInt64(value: Int64) method #

      Writes an int64, as a varint.

    • Public Method WriteUInt32(value: UInt32) method #

      Writes a uint32, as a varint.

    • Public Method WriteUInt64(value: UInt64) method #

      Writes a uint64, as a varint.

    • Public Method WriteSInt32(value: Int32) method #

      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.

    • Public Method WriteSInt64(value: Int64) method #

      Writes a sint64, zigzagged, so a small negative number takes as few bytes as a small positive one.

    • Public Method WriteBool(value: Bool) method #

      Writes a bool, as a varint of 1 or 0.

    • Public Method WriteFixed32(value: UInt32) method #

      4 bytes, the lowest first.

    • Public Method WriteFixed64(value: UInt64) method #

      8 bytes, the lowest first.

    • Public Method WriteSFixed32(value: Int32) method #

      Writes an sfixed32, as its 4 bytes, the lowest first.

    • Public Method WriteSFixed64(value: Int64) method #

      Writes an sfixed64, as its 8 bytes, the lowest first.

    • Public Method WriteFloat(value: Float32) method #

      A float's IEEE 754 bits, in 4 bytes.

    • Public Method WriteDouble(value: Float64) method #

      A double's IEEE 754 bits, in 8 bytes.

    • Public Method WriteBytes(value: UInt8[]) method #

      Its length, then its bytes.

    • Public Method WriteString(value: String) method #

      Its UTF-8's length, then its UTF-8.

    • Public Method WriteRaw(value: UInt8[]) method #

      Bytes as they are, like the fields a message didn't know, which it keeps.

    • Public Method BeginLength(): Int method #

      Starts what a length goes before, like a message inside another or a packed field's values, and gives where, for EndLength.

    • @PanicsAtCaller Public Method EndLength(start: Int) method #

      Puts the length of what was written since BeginLength gave start before it. Panics when start isn't where a BeginLength left room for a length.

    • Public Method Finish(): UInt8[] method #

      What it has written, after which it starts again, empty.

    Report an issue with this page or with FutureBlitz on GitHub.