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?
On Thu, Mar 23, 2023 at 9:44 PM DinoStray ***@***.***> wrote:
I change proto definition
bytes xxx
to
string xxx
then everything is ok.
I think there is some bug while use bytes for nodejs.
—
Reply to this email directly, view it on GitHub
<#167 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABTJXHMHLV3RWS6QODDXC3W5URENANCNFSM6AAAAAAWD3CKAQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
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: