If you know you are reading a message, but have already read the length of the message OR you're reading fields of the top level data, then this method is the alternative. It's often used by sub-classes So that it can be instationated prior to reading the message.
user defined input function to parse the message fields
The class to mutate given field data
the end position of the message in the buffer
Ex.
export class MapboxVectorLayer {
constructor(pbf: Protobuf, end: number) {
this.#pbf = pbf;
pbf.readFields(this.#readLayer, this, end);
}
#readLayer(tag: number, layer: MapboxVectorLayer, pbf: Protobuf): void {
if (tag === 15) layer.version = pbf.readVarint();
else if (tag === 1) layer.name = pbf.readString();
// ...
}
}
Reads a message from the buffer. Sometimes it's easier to manage sub structures so that the current method can build multiples of an entire structure/class. If you you are at the top level, or parsing the message inside a class, then
user defined input function
an instance of the class you are reading into
readVarint for better performance
Protobuffer Reader
Description
Create a new PBF instance read to it. Follows the early Protobuf spec supporting various types of encoding including messages (which are usually representative of class objects).
Usage
Reading: