type_url should be an identifier of the type of the protobuf message you're
transcoding. By default the url of a specific message type looks like
*I'd imagine the prefix might be configurable to something other than
*type.googleapis.com*, but can't say for sure, haven't tried changing it.
A TypeResolver instance can be created with the function
*declared in type_resolver_util.h:
*NewTypeResolverForDescriptorPool *takes a pointer to a DescriptorPool. If
the generated code for the relevant type of message has been compiled as
part of your binary then its descriptor should be in the generated
descriptor pool so you should just use that. Otherwise, you can build the
descriptor and the pool from a FileDescriptorProto.
Usage might look something like this:
using namespace google::protobuf;
using namespace google::protobuf::util;
void foo(const Message& msg)
TypeResolver* resolver = NewTypeResolverForDescriptorPool(
Status status = BinaryToJsonString(resolver, "type.googleapis.com/" + msg.
GetTypeName(), msg.SerializeAsString(), &json_output);
std::cout << json_output;
I hope this helps.
On Tuesday, April 5, 2016 at 9:23:17 PM UTC+3, Zachary Deretsky wrote:
> could you post and example and some explanation on how to (de)serialize
> proto3 to JSON using
> LIBPROTOBUF_EXPORT util::Status BinaryToJsonString(
> TypeResolver* resolver,
> const string& type_url,
> const string& binary_input,
> string* json_output,
> const JsonOptions& options);
> How to create TypeResolver and what is type_url?
> I am asking because you seem to be the only one with expertise on the
> Thank you, Zach.
> On Thursday, November 26, 2015 at 12:51:07 AM UTC-8, Ron Ben-Yosef wrote:
>> On Wednesday, November 25, 2015 at 8:56:51 PM UTC+2, Feng Xiao wrote:
>>> Thanks for the explanation. Could you help file a bug for this on
>>> protobuf github site? If you know of an solution to this, you are also
>>> welcomed to send us a pull request.
>> Sure, no problem.
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
To post to this group, send email to firstname.lastname@example.org.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.