Re: [protobuf] Are wrapper.proto messages automatically packed / unpacked with

2017-10-24 Thread Josh Humphries
It sounds like you are observing the expected behavior regarding how these
wrapper types are marshalled/unmarshalled to/from JSON:
https://developers.google.com/protocol-buffers/docs/proto3#json

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



*Josh Humphries*
jh...@bluegosling.com

On Tue, Oct 24, 2017 at 5:54 AM, Jack Wootton  wrote:

> 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
>
> https://github.com/cloudendpoints/esp/blob/ee24633d0e6837f7d7fa05302f4ea6
> bd419a7d8e/src/api_manager/utils/marshalling.cc#L53. For example:
>
>
> 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::Bina
> ryToJsonString( 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;
> }
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

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


[protobuf] Are wrapper.proto messages automatically packed / unpacked with

2017-10-24 Thread Jack Wootton
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

https://github.com/cloudendpoints/esp/blob/ee24633d0e6837f7d7fa05302f4ea6bd419a7d8e/src/api_manager/utils/marshalling.cc#L53.
 
For example:


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

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