pbf icon indicating copy to clipboard operation
pbf copied to clipboard

Error using google.protobuf.Any

Open anri-asaturov opened this issue 5 years ago • 8 comments

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?

anri-asaturov avatar Dec 19 '19 13:12 anri-asaturov

You may need to manually import the type.

https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto

kjvalencik avatar Dec 19 '19 14:12 kjvalencik

@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

anri-asaturov avatar Dec 19 '19 14:12 anri-asaturov

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 avatar Dec 19 '19 14:12 kjvalencik

@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)

anri-asaturov avatar Dec 19 '19 14:12 anri-asaturov

Could you check out this sandbox please? https://repl.it/repls/GleamingWhimsicalInformationtechnology

anri-asaturov avatar Dec 19 '19 14:12 anri-asaturov

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);

anri-asaturov avatar Dec 19 '19 22:12 anri-asaturov

Did (@anri-asaturov) you find solution? I have same problem, but with google.protobuf.BytesValue (in wrapper.proto)?

janch11 avatar Jan 31 '20 08:01 janch11

@janch11 no, I had to fork/rewrite pbf to my needs since there was even more issues not aligning with my use case

anri-asaturov avatar Jan 31 '20 10:01 anri-asaturov