-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
handle 'type.googleapis.com/' string #850
Comments
Hi @FoghostCn , did you manage to find out how to make this working? |
@dobryanskyy I have to override the two method protobufjs.wrappers['.google.protobuf.Any'] = {
fromObject(object) {
if (object && object["@type"]) {
const t = object["@type"];
const type = this.lookup(t);
if (type) {
return this.create({
type_url: `type.googleapis.com/${t}`,
value: type.encode(type.fromObject(object)).finish()
});
}
}
return this.fromObject(object);
},
toObject(message, options) {
if (options && options.json && message.type_url && message.value) {
const type = this.lookup(message.type_url.replace('type.googleapis.com/', ''));
if (type) {
message = type.decode(message.value);
}
}
if (!(message instanceof this.ctor) && message instanceof protobufjs.Message) {
const object = message.$type.toObject(message, options);
const name = message.$type.fullName;
object["@type"] = name.charAt(0) === '.' ? name.substr(1) : name;
return object;
}
return this.toObject(message, options);
}
}; |
great, thanks |
@dcodeIO, are there any plans to add the |
+1 I'm also running into this issue. Ive tested out the PR #1068 locally and its working great. |
protobuf.js version: 6.8.0
in google's any.proto file I find this document:
and I have seen your code about
any
typefromObject
andtoObject
method didn't handletype.googleapis.com/
stringactually
Msg.decode(buffer).toJSON()
didn't auto decodeAny
type withtype_url =type.googleapis.com/myMsg
but can auto decode.myMsg
did I missing something?
The text was updated successfully, but these errors were encountered: