Skip to content
FutureBlitz

    Install

    Import std.data.protobuf

    ProtoText

    std.data.protobuf

    class

    Public Class ProtoText

    Writes a message as protobuf's text format, on one line, as a message's ToString gives it: name: "Ada" id: 7 phone { number: "555" }. Each field goes in with its name, a message's between BeginMessage and EndMessage.

    Examples

    Local text = ProtoText()
    text.WriteString("name", "Ada")
    text.Write("id", "7")
    text.BeginMessage("phone")
    text.WriteString("number", "555")
    text.EndMessage()
    Expect(text.Finish() == "name: \"Ada\" id: 7 phone {{ number: \"555\" }}")

    std/data/protobuf.fb, line 630

    • Public New() constructor #

      A new ProtoText, with nothing written.

    • Public Method Write(name: String, value: String) method #

      name: value, for a value that's text already, like a number or an enum's name.

    • Public Method WriteBool(name: String, value: Bool) method #

      name: true or name: false.

    • Public Method WriteFloat(name: String, value: Float32) method #

      A float as text format has it: its shortest form, or inf, -inf, or nan.

    • Public Method WriteDouble(name: String, value: Float64) method #

      A double as text format has it: its shortest form, or inf, -inf, or nan.

    • Public Method WriteString(name: String, value: String) method #

      A string in quotes, with C's escapes for quotes, backslashes, and control characters; the rest of its UTF-8 stays as it is.

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

      Bytes in quotes, with C's escapes, and each byte that isn't printable ASCII in octal.

    • Public Method BeginMessage(name: String) method #

      Starts a message's fields: name {.

    • Public Method EndMessage() method #

      Ends the message BeginMessage started: }.

    • @PanicsAtCaller Public Method WriteUnknown(unknown: UInt8[]) method #

      The fields a message didn't know, by their numbers, as text format shows them: a varint as its number, a 4-byte or 8-byte value in hex, a length-delimited one as bytes in quotes, and a group between braces. Panics when unknown isn't fields, as a reader's Skip keeps them.

    • Public Method Finish(): String method #

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

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