Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using google.protobuf.Any #117

Open
anri-asaturov opened this issue Dec 19, 2019 · 9 comments
Open

Error using google.protobuf.Any #117

anri-asaturov opened this issue Dec 19, 2019 · 9 comments

Comments

@anri-asaturov
Copy link

anri-asaturov commented Dec 19, 2019

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?

@kjvalencik
Copy link
Collaborator

kjvalencik commented Dec 19, 2019

You may need to manually import the type.

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

@anri-asaturov
Copy link
Author

@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

@kjvalencik
Copy link
Collaborator

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.

@anri-asaturov
Copy link
Author

@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
Copy link
Author

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

@anri-asaturov
Copy link
Author

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

@janch11
Copy link

janch11 commented Jan 31, 2020

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

@anri-asaturov
Copy link
Author

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

@kenjichanhkg
Copy link

I have the same problem with Any too. How exactly can I fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants