Skip to content
FutureBlitz

    Install

    Import std.data.protobuf

    ProtoReader

    std.data.protobuf

    class

    Public Class ProtoReader

    Reads protobuf's wire format from bytes, a field at a time: ReadTag, then the value its field has. A message inside another is read between BeginMessage and EndMessage, and a packed field's values between BeginPacked and EndPacked, which keep the reader inside them.

    Examples

    Local reader = ProtoReader([0x08, 0x96, 0x01, 0x12, 0x02, 0x68, 0x69] As UInt8[])
    Expect((Try reader.ReadTag()) == ProtoTag(1, WIRE_VARINT))
    Expect((Try reader.ReadInt32()) == 150)
    Expect((Try reader.ReadTag()) == ProtoTag(2, WIRE_LENGTH))
    Expect((Try reader.ReadString()) == "hi")
    Expect(reader.AtEnd)

    std/data/protobuf.fb, line 272

    • Public New(bytes: UInt8[]) constructor #

      A ProtoReader of bytes, the wire format of a message.

    • Public Property AtEnd: Bool property #

      Whether what's being read has no more bytes: the bytes, or the message or packed field it's inside.

    • Public Property Position: Int property #

      Where it's reading, from the first byte, 0.

    • Public Property TagStart: Int property #

      Where the last tag read starts, for KeepFrom.

    • Public Method More(ending: UInt32): Bool Throws ParseError method #

      Whether there's another field to read before the end of what's being read, or in a group, whose end tag ending is, before that tag, which has to come first. ending is 0 outside a group.

    • Public Method ReadTag(): UInt32 Throws ParseError method #

      A field's tag: its number and wire type, in up to 5 bytes, as protobuf's readers take one. Throws a ParseError for field 0, a number past PROTO_FIELD_LIMIT, or wire type 6 or 7, which aren't protobuf's.

    • Public Method ReadVarint(): UInt64 Throws ParseError method #

      An unsigned varint, of up to 10 bytes. Bits past 64 are dropped, as protobuf's readers drop them.

    • Public Method ReadInt32(): Int32 Throws ParseError method #

      An int32, from a varint's low 32 bits.

    • Public Method ReadInt64(): Int64 Throws ParseError method #

      An int64, from a varint.

    • Public Method ReadUInt32(): UInt32 Throws ParseError method #

      A uint32, from a varint's low 32 bits.

    • Public Method ReadUInt64(): UInt64 Throws ParseError method #

      A uint64, from a varint.

    • Public Method ReadSInt32(): Int32 Throws ParseError method #

      A zigzagged sint32, from a varint's low 32 bits.

    • Public Method ReadSInt64(): Int64 Throws ParseError method #

      A zigzagged sint64, from a varint.

    • Public Method ReadBool(): Bool Throws ParseError method #

      A bool: any varint but 0 is True.

    • Public Method ReadFixed32(): UInt32 Throws ParseError method #

      A fixed32's 4 bytes, the lowest first.

    • Public Method ReadFixed64(): UInt64 Throws ParseError method #

      A fixed64's 8 bytes, the lowest first.

    • Public Method ReadSFixed32(): Int32 Throws ParseError method #

      An sfixed32's 4 bytes, the lowest first.

    • Public Method ReadSFixed64(): Int64 Throws ParseError method #

      An sfixed64's 8 bytes, the lowest first.

    • Public Method ReadFloat(): Float32 Throws ParseError method #

      A float's 4 bytes, the lowest first.

    • Public Method ReadDouble(): Float64 Throws ParseError method #

      A double's 8 bytes, the lowest first.

    • Public Method ReadLength(): Int Throws ParseError method #

      A length-delimited field's length, in up to 5 bytes, which its bytes have to fit in.

    • Public Method ReadBytes(): UInt8[] Throws ParseError method #

      A length and the bytes after it, in a new array.

    • Public Method ReadString(): String Throws ParseError method #

      A length and the UTF-8 after it. Throws a ParseError when it isn't UTF-8, which every String is.

    • Public Method BeginMessage(): Int Throws ParseError method #

      Starts reading a message inside another, after its tag, and gives where the one around it ends, for EndMessage. Throws a ParseError when it's nested more than PROTO_DEPTH_LIMIT deep, or doesn't fit.

    • Public Method EndMessage(outer: Int) method #

      Goes on with the message around one BeginMessage started, which gave outer.

    • Public Method BeginGroup() Throws ParseError method #

      Starts reading a group, after its start tag, which it ends at its own end tag. Throws a ParseError when it's nested more than PROTO_DEPTH_LIMIT deep.

    • Public Method EndGroup() method #

      Goes on with the message around a group BeginGroup started.

    • Public Method BeginPacked(size: Int): Int Throws ParseError method #

      Starts reading a packed field's values, after its tag, and gives where what's around it ends, for EndPacked. size is each value's, 4 or 8, or 0 for varints, whose bytes vary.

    • Public Method EndPacked(outer: Int) method #

      Goes on with the message around a packed field BeginPacked started, which gave outer.

    • Public Method Skip(tag: UInt32, unknown: UInt8[]) Throws ParseError method #

      Reads past the value of a field the message doesn't know, whose tag was just read, and keeps the field, its tag too, in unknown, as it was written. A group's fields go along with it. Throws a ParseError for an end tag without its group.

    • Public Method Keep(unknown: UInt8[]) method #

      Keeps the field just read, its tag too, in unknown, as it was written: one whose value the message has no place for, like a number that isn't one of a closed enum's values.

    • @PanicsAtCaller Public Method KeepFrom(start: Int, unknown: UInt8[]) method #

      Keeps the bytes from start, where TagStart said a field's tag was, up to where it's reading, in unknown: a map's entry whose value is a closed enum's number it doesn't name. Panics when start is past where it's reading, or before the bytes.

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