-
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
"Google Protobuf Any" javscript example #1082
Comments
I've found the solution by inspect an packed Message! For an easy usage, you can run these on first initialization and store the protobuf.load('google/protobuf/any.proto', function(err, root) {
if(err) {
throw err;
}
global.Any = root.lookup('Any');
}); And here is an Example: var test = Any.create({
type_url: 'whatever',
value: <Buffer>
});
console.log('Instance', test);
console.log('Packed', Any.encode(test).finish()); |
hi @Bizarrus , a cordial greeting. a favor, what would be an example of the value in "< Buffer >"? |
If you wan't an real example, here is it: Demo.proto
Script const protobuf = require('protobufjs');
protobuf.load('google/protobuf/any.proto', function(error, root) {
if(error) {
throw error;
}
global.Any = root.lookup('Any');
protobuf.load('Demo.proto', function(error, root) {
if(error) {
throw error;
}
let Demo = root.lookup('Demo');
let test = Demo.create({
demo: 'Hello World'
});
console.log(test);
var any = Any.create({
type_url: 'whatever',
value: test,
// value: Demo.encode(test).finish() // Or as packed buffer
});
console.log('Instance', any);
console.log('Packed', Any.encode(any).finish());
});
}); |
hi all, a cordial greeting, please @Bizarrus , a question, in that example i always get:
Why can it be? |
Can anyone please provide an example for https://developers.google.com/protocol-buffers/docs/proto3#any
I couldn't able to use the example provided in #435
The text was updated successfully, but these errors were encountered: