Skip to content
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

Decode delimited is getting the message length wrong #1955

Open
BenjaminBalleux opened this issue Dec 14, 2023 · 0 comments
Open

Decode delimited is getting the message length wrong #1955

BenjaminBalleux opened this issue Dec 14, 2023 · 0 comments

Comments

@BenjaminBalleux
Copy link

BenjaminBalleux commented Dec 14, 2023

protobuf.js version: <7.2.5>

Hello,

I am reading many messages from a file. The buffer read from the file looks like :
<0a a7 23 08 97 f8 ce ab 06 ...

It starts with "0a" which, from my understanding, indicates that the buffer is length delimited. Then comes the size of the message, then the actuel message, and repeat.

My problem here is that the decodeDelimited method seems to use the first byte 0a as the length of the message instead of skipping it, and throw an error.
Should I manually skip this byte before decoding each message ? This works, but I'm not familiar with Protobuf and I may be misunderstanding something.

Here is the code I'm using to decode

// Load protobuf structure file.
const root: Protobuf.Root = await Protobuf.load(__dirname + '/structure.proto');

const GroupByTimestamp: Protobuf.Type = root.lookupType('socomecprotobuf.GroupByTimestamp');

const buffer = await this.readProtoFile(path);

const reader = Protobuf.Reader.create(buffer);
const messages = [];
while (reader.pos < reader.len) {
	const tag = reader.int32();
	if (tag !== 10) {
		throw Error(/** */);
	}
	const next = GroupByTimestamp.decodeDelimited(reader);
	messages.push(next);
}
return messages;

Any insight about this ? Am I doing something wrong or should I really do that this way ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant