Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

Commit

Permalink
Set packed=true for all repeated packable types
Browse files Browse the repository at this point in the history
  • Loading branch information
cyraxx committed Jul 27, 2016
1 parent 99e0330 commit 17b5975
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pogo-protos.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@ fs.readdirSync(protoDir)
.filter(filename => filename.match(/\.proto$/))
.forEach(filename => protobuf.loadProtoFile(protoDir + '/' + filename, builder));

// Recursively add the packed=true to all packable repeated fields.
// Repeated fields are packed by default in proto3 but protobuf.js incorrectly does not set the option.
// See also: https://github.com/dcodeIO/protobuf.js/issues/432
function addPackedOption(ns) {
if (ns instanceof protobuf.Reflect.Message) {
ns.getChildren(protobuf.Reflect.Field).forEach(field => {
if (field.repeated && protobuf.PACKABLE_WIRE_TYPES.indexOf(field.type.wireType) != -1) {
field.options.packed = true;
}
});
} else if (ns instanceof protobuf.Reflect.Namespace) {
ns.children.forEach(addPackedOption);
}
}
addPackedOption(builder.lookup('POGOProtos'));

module.exports = builder.build("POGOProtos");

0 comments on commit 17b5975

Please sign in to comment.