-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Encode and Decode Delimited #531
Comments
Try: var reader = new protobuf.BufferReader(output);
// here I am trying to decode same thing but its giving false output.
header.decodeDelimited(reader)
singleParam.decodeDelimited(reader) When using 6.1.0, this is recommended instead: var reader = protobuf.Reader.create(output); |
am I encoding right? is this the right way to encodeDelimited? Plus, I tried this and It didn't work, still getting the same error. Nothing changed. :( |
With 6.1.0, that's how I'd write it: const header = root.lookup('header');
const singleParam = root.lookup('singleParam');
const writer = protobuf.Writer.create(); // or: new protobuf.BufferWriter();
header.encodeDelimited({
commandType: 1,
commandID: 1
}, writer);
singleParam.encodeDelimited({
parameter: 100 // not a string
}, writer);
const buffer = writer.finish();
const reader = protobuf.Reader.create(buffer); // or: new protobuf.BufferReader(buffer);
let myHeader = header.decodeDelimited(reader);
let myParam = singleParam.decodeDelimited(reader); Note: |
// This isnt working
const writer = protobuf.Writer.create(); // But this one is working fine.
const writer = new protobuf.Writer(); still getting error |
I think there's something wrong with encoding. I am using Protobuf's C lib in Arduino, and its returning me this bytestream
This decodes correctly using method above. but when I encode from above method, I get this
|
|
Please try again with the current master version. |
Working perfectly fine now. Thanks 👍 But how do I update npm now :P |
6.1.0 is now also on npm! |
I am trying to encode/decode message using encodeDelimited and decodeDelimited functions.
I want to read header message and then decide which message to decode it. and same goes for encoding, I only want to send encode and send the message which I client needs. for example, if I am invoking a command with single param, I send only single param, and I decide it using my header. I need to use encodeDelimited to encode header and message with it so that my client can see which command I've sent and can read accordingly.
same goes for Javascript side as well. if the client sends me some encoded message, I need to decode it accordingly.
for reference, I've posted by Protobuf file here.
and this is my javascript code:
and on decoding I am getting same error again and again. ie.
invalid wire type: 4
The text was updated successfully, but these errors were encountered: