-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
protobuf.js version - 7.5.0;
nodejs - 20.15.0.
The library encodes repeated fields as expanded by default. The issue is similar to this.
Code example:
import proto from 'protobufjs';
// Proto file
const proto_file = `syntax = "proto3";
message TestMessage{
uint32 num = 1;
repeated uint32 array = 2;
}`;
const array = new Array(3);
array.push(1);
array.push(2);
array.push(3);
const data = {
num: 1,
array
};
let obj;
const root = proto.parse(proto_file, { keepCase: true }).root; // or use Root#load
obj = root.lookupType('TestMessage');
const converted = obj.fromObject(data);
const result = obj.encode(converted).finish();
const temp = new Uint8Array(result);
console.log(temp.toString());Actual result:
8,1,16,0,16,0,16,0,16,1,16,2,16,3
Expected result:
8,1,18,3,1,2,3
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels