Open
Description
protobuf.js version: 6.8.6
When I attempt to encode a message from a Google well known type (like google.protobuf.Struct
) I get an empty field in the decoded message IF my path includes google/protobuf
.
Is this a bug or do we need to provide the path in some other way. I assume the problem starts when loading the commons wrapper here.
const protobuf = require('protobufjs');
let root = new protobuf.Root();
const protoFilePath = '<path to a file which imports google.protobuf.Struct>';
const protoRoot = .............;
root.resolvePath = function (origin, target) {
// ignore the same file
if (target == protoFilePath) {
return protoFilePath;
}
// Resolved target path for the import files
return protoRoot + target;
};
const struct = {
fields: {
label: {
struct_value: {
fields: {
another_label: {
number_value: 10
}
}
}
}
}
};
root = root.loadSync(protoFilePath);
const MyType = root.lookupType('MyType');
const msg = MyType.create({
struct_message: struct
});
const buffer = MyType.encode(msg).finish();
console.log('Decoded message', MyType.decode(buffer));
Decoded message: Struct { fields: { label: Value {} } } }
Note: this was working with protobuf.js
version 5.