-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to convert to buffer in node.js? #34
Comments
The var buf = Buffer.alloc(8);
// BE
buf.writeInt32BE(l.high, 0);
buf.writeInt32BE(l.low, 4);
// or LE
buf.writeInt32LE(l.low, 0);
buf.writeInt32LE(l.high, 4);
console.log(buf.toString("base64")); |
Thanks! :) Regarding LE/BE... since this is dependent on the architecture of the chip, does protobuf specify which order the bytes are in? Might I assume that a sane developer would choose "network order", that being BE, right? I'll have to google a little bit. I'm confused as to why node doesn't have a whatever-my-cpu-wants option... |
protobuf always uses LE. Generally spoken, with JavaScript you always have to specify byte order explicitly. |
I need to take a long (from protobufjs) and convert it to base64 using node.js' Buffer... can you add the one-liner to an examples section or something?
I'm just a little confused as to how to do it and, unfortunately, I don't have a reference byte sequence with corresponding base64 string for what I'm working on so trial and error is... confusing... :-/
I was expecting something like
but that didn't yield valid values.
The text was updated successfully, but these errors were encountered: