You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What are you trying to do with the output? Fundamentally, serializeBinary is giving you a Uint8Array, which Buffer.from seems ok with. However, Buffer.toString assumes utf8 encoding, which you can't guarantee.
I'm not particularly experience with node, but at a glance I think Buffer/Uint8Array in this circumstance is roughly the same as SerializeAsString's produced std::string (i.e. bag of bits).
If you're trying to pass this off to some API that truly needs a string, then I think you need to Base64 encode.
The problem is utf8 encoding as dibenede said. When you change your type to
string that will get utf8 encoded when you call serializeBinary(), so when
you wrap it in a buffer and call toString that will be reversed.
See
https://nodejs.org/api/buffer.html#buftostringencoding-start-end
What are you actually trying to do? Why do you need a string?
In C++, I can call protobuf_object.SerializeAsString().
Which method is the same as above in nodejs?
The following code is not correct.
The text was updated successfully, but these errors were encountered: