mapbox / pbf

A low-level, lightweight protocol buffers implementation in JavaScript.
BSD 3-Clause "New" or "Revised" License
801 stars 107 forks source link

Is the encoding method here different than other protobufs? #105

Closed kkailiwang closed 4 months ago

kkailiwang commented 5 years ago

My project takes in encoded proto strings (which were created from google's protobuf) and I just need a package that can decode them into javascript. Is this package's decoding process only for messages encoded by mapbox/pbf?

I ask because it works when I encode and then decode a message, like: let pbf = new pbf(); pbf.writeString('hi'); pbf.finish(); return pbf.readString();

but not when I just decode a message (this is embedded):

let pbf = new Pbf();
pbf.writeRawMessage(dataString); 
pbf.finish();
//or just new Pbf(dataString)

const readFields = pbf.readFields(function(tag) { 
    const tagNeeded = tagArray[0];  
    if (tag === tagNeeded) {
        if (tagArray.length == 1) {
          return pbf.readFloat();
        }
        tagArray.splice(0, 1); 
        pbf.readMessage(readFields, {});

    }, {});
}
mourner commented 4 months ago

Sorry for for commenting on a very old issue — pbf is meant to be fully compatible with all other tools. If there are any issues with pbf decoding a protobuf message, please report and issue and provide a sample protobuf file that doesn't work. There was not test case here so I can't tell what the issue is.