Protobuf: Assertion failed

Created on 27 Aug 2017  路  9Comments  路  Source: protocolbuffers/protobuf

I have a problem with JavaScript protobuf (version 3.4.0 , )

in the following code

var message = MyMessage.deserializeBinary(bytesFromServer);

When I have a repeated uint64 field I have Assertion failed error, in other cases I have no problem

I know bytesFromServer is correct , other languages can deserialize the message

bug javascript

Most helpful comment

@xense unofficial https://github.com/dcodeIO/ProtoBuf.js/ library is better that officially version
Trust me!

All 9 comments

Help please

I had the same issue.

It was also because of the deserializeBinary() method.
I was actually deserializing the wrong object and I had this error.

So check correctly whether you are working on the correct object beforehand...

@Tenmak I just reopen issue
I know bytesFromServer is correct , other languages can deserialize the message

@sm2017 i am also facing the same issue. do you have any solution for this

Same issue. Other languages can deserialize some binary, but js get AsertitionError

@xense unofficial https://github.com/dcodeIO/ProtoBuf.js/ library is better that officially version
Trust me!

Made a patch using npm replace tool, run it every time after yarn install. It sets DEBUG flag to false and disables assertions. Everything works great now!
Below are package.json additions

"scripts": {
    "patch-google-proto": "replace goog.DEBUG=!0 goog.DEBUG=!1 node_modules/google-protobuf/google-protobuf.js",
},
"devDependencies": {
    "replace": "^1.1.1"
}

PS. @sm2017 I already have a huge project running on official library, so I cannot switch to dcodeIO.

I've run into the same issue, and found that the JS deserializer currently doesn't correctly implement the following behaviors described in https://developers.google.com/protocol-buffers/docs/encoding:

Protocol buffer parsers must be able to parse repeated fields that were compiled as packed as if they were not packed, and vice versa.

(Compatibility between packed and unpacked fields is broken in both directions. This also breaks repeated uint64 fields, as some implementations incorrectly default to unpacked even with proto3)

Note that although there's usually no reason to encode more than one key-value pair for a packed repeated field, encoders must be prepared to accept multiple key-value pairs. In this case, the payloads should be concatenated.

(As the specification states, this one probably isn't an issue in practice, but the implementation is still incorrect)

Was this page helpful?
0 / 5 - 0 ratings