Skip to content

Repeated fields not packed by default #2115

@aleksej825

Description

@aleksej825

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions