Import std.data.protobuf
ProtoReader
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
-
A ProtoReader of
bytes, the wire format of a message. -
Whether what's being read has no more bytes: the bytes, or the message or packed field it's inside.
-
Where it's reading, from the first byte, 0.
-
Where the last tag read starts, for KeepFrom.
-
Whether there's another field to read before the end of what's being read, or in a group, whose end tag
endingis, before that tag, which has to come first.endingis 0 outside a group. -
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.
-
An unsigned varint, of up to 10 bytes. Bits past 64 are dropped, as protobuf's readers drop them.
-
An int32, from a varint's low 32 bits.
-
An int64, from a varint.
-
A uint32, from a varint's low 32 bits.
-
A uint64, from a varint.
-
A zigzagged sint32, from a varint's low 32 bits.
-
A zigzagged sint64, from a varint.
-
A bool: any varint but 0 is True.
-
A fixed32's 4 bytes, the lowest first.
-
A fixed64's 8 bytes, the lowest first.
-
An sfixed32's 4 bytes, the lowest first.
-
An sfixed64's 8 bytes, the lowest first.
-
A float's 4 bytes, the lowest first.
-
A double's 8 bytes, the lowest first.
-
A length-delimited field's length, in up to 5 bytes, which its bytes have to fit in.
-
A length and the bytes after it, in a new array.
-
A length and the UTF-8 after it. Throws a ParseError when it isn't UTF-8, which every String is.
-
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.
-
Goes on with the message around one BeginMessage started, which gave
outer. -
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.
-
Goes on with the message around a group BeginGroup started.
-
Starts reading a packed field's values, after its tag, and gives where what's around it ends, for EndPacked.
sizeis each value's, 4 or 8, or 0 for varints, whose bytes vary. -
Goes on with the message around a packed field BeginPacked started, which gave
outer. -
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 endtagwithout its group. -
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. -
Keeps the bytes from
start, where TagStart said a field's tag was, up to where it's reading, inunknown: a map's entry whose value is a closed enum's number it doesn't name. Panics whenstartis past where it's reading, or before the bytes.
Report an issue with this page or with FutureBlitz on GitHub.