pbf
pbf copied to clipboard
Error using google.protobuf.Any
Sandbox: https://repl.it/repls/GleamingWhimsicalInformationtechnology
pbf fails to compile this proto
message RequestEnvelope {
string correlationId = 1;
string callPath = 2;
google.protobuf.Any payload = 3;
}
with
./node_modules/pbf/compile.js:157
default: throw new Error('Unexpected type: ' + field.type);
Error: Unexpected type: google.protobuf.Any
at compileFieldRead (./node_modules/pbf/compile.js:157:28)
Is it known that it's not supported or am I doing something wrong?
You may need to manually import the type.
https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto
@kjvalencik do you mean like copy and paste the any.proto content to my proto?
because the file exists in ./google/protobuf
folder relative to my proto
You shouldn't need to copy if it's already there. Do you have an import line for it? Only paths are supported when importing in pbf.
@kjvalencik
option go_package = "go";
package wire;
import "google/protobuf/any.proto";
message RequestEnvelope {
string correlationId = 1;
string callPath = 2;
google.protobuf.Any payload = 3;
}
this is the full file. The ./google/protobuf/any.proto file exists (otherwise I get ENOENT)
Could you check out this sandbox please? https://repl.it/repls/GleamingWhimsicalInformationtechnology
Ok so what i managed to figure out is that when proto is parsed, it looks like this
syntax: 3,
package: 'wire',
imports: [ 'google/protobuf/any.proto' ],
enums: [ { name: 'EnvelopeType', values: [Object], options: {} } ],
messages: [
{
name: 'RequestEnvelope',
enums: [],
extends: [],
messages: [],
fields: [Array],
extensions: null
},
{
name: 'ResponseEnvelope',
enums: [],
extends: [],
messages: [],
fields: [Array],
extensions: null
},
{
name: 'Any',
enums: [],
extends: [],
messages: [],
fields: [Array],
extensions: null
}
],
options: { go_package: 'go' },
extends: []
}
Note the Any
- it's in the root, like I defined it myself.
But getType
function expects Any descriptor to be nested in google:{ protobuf: {Any: ...}}
const path = field.type.split('.');
const ret = path.reduce(function(ctx, name) {
return ctx && ctx[name];
}, ctx);
Did (@anri-asaturov) you find solution? I have same problem, but with google.protobuf.BytesValue (in wrapper.proto)?
@janch11 no, I had to fork/rewrite pbf to my needs since there was even more issues not aligning with my use case