Are wrapper.proto messages automatically packed / unpacked with

339 views
Skip to first unread message

Jack Wootton

unread,
Oct 24, 2017, 5:54:51 AM10/24/17
to Protocol Buffers
I'm using wrappers.proto in my own API that sits behind Google's Extensible Service Proxy. The proxy trans-codes JSON <-> ProtoBuf. Code for trans-coding is



Status ProtoToJson(const Message& message, std::string* result, int options) {
 
::google::protobuf::util::JsonPrintOptions json_options;
 
if (options & JsonOptions::PRETTY_PRINT) {
   json_options
.add_whitespace = true;
 
}
 
if (options & JsonOptions::OUTPUT_DEFAULTS) {
   json_options
.always_print_primitive_fields = true;
 
}
 
// TODO: Skip going to bytes and use ProtoObjectSource directly.
 
::google::protobuf::util::Status status = ::google::protobuf::util::BinaryToJsonString( GetTypeResolver(), GetTypeUrl(message),
message
.SerializeAsString(),
   result
, json_options);
   
return Status::FromProto(status);
 
}
 
Note the call to message.SerializeAsString()

I've noticed my web client receives any wrapper messages, without their wrapper. For example, my server constructs a message 

message NumberOptions {
    google
.protobuf.Int32Value minimum = 1;
    google
.protobuf.Int32Value maximum = 2;
}

with the following values:

minimum {
  value
: 1
}
maximum
{
  value
: 100
}

However, after my message passes through the ESP (and is serislised to JSON), my client receives:

minimum: 1
maximum
: 100

Does SerializeAsString automatically unpack any wrapper messages? If so, can I also send JSON:

minimum
: 1
maximum
: 100

..and expect wrappers to be created (if the message is defined to use wrappers), i.e.

message NumberOptions {
    google
.protobuf.Int32Value minimum = 1;
    google
.protobuf.Int32Value maximum = 2;
}

Josh Humphries

unread,
Oct 24, 2017, 11:07:04 AM10/24/17
to Jack Wootton, Protocol Buffers
It sounds like you are observing the expected behavior regarding how these wrapper types are marshalled/unmarshalled to/from JSON:

They get "unboxed" in JSON, as do various other well-known types such as structs, timestamps, and durations.


----
Josh Humphries
jh...@bluegosling.com

--
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 protobuf+unsubscribe@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages