Skip to content
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

Use RFC 3339 string representation of google.protobuf.Timestamp #98

Open
shaneqld opened this issue Jul 10, 2019 · 4 comments
Open

Use RFC 3339 string representation of google.protobuf.Timestamp #98

shaneqld opened this issue Jul 10, 2019 · 4 comments

Comments

@shaneqld
Copy link

@shaneqld shaneqld commented Jul 10, 2019

When using type google.protobuf.Timestamp, BloomRPC maps this to an object, e.g.:

"create_time": {
  "seconds": "1562723637",
  "nanos": 928852400
}

However, the Google API Design Guide specifies that the string representation should be RFC 3339 format, e.g. "2014-07-30T10:43:17Z"

This JSON mapping is used by Cloud Endpoints and Envoy grpc-json transcoding. Regardless, an RFC 3339 string is much easier to work with by hand than a Unix timestamp.

I'd like to submit this as a feature/request for changing how timestamps are transcoded to/from json. ps- love the tool, very handy!

@fenos

This comment has been minimized.

Copy link
Contributor

@fenos fenos commented Jul 10, 2019

@shaneqld Hi there!

I'm not sure i follow, the google.protobuf.Timestamp message type has got 2 fields, which represent the date, you can see it here:

https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto#L127

That's why bloomrpc tries to fill the fields for this type.

i think you are looking for is a kind of helper function which will convert a date RFC 3339 into this kind of message type?

ex (not implemented just yet):

{
    "date": "{{dateToProtoTimestamp('2014-07-30T10:43:17Z')}}"
}
@shaneqld

This comment has been minimized.

Copy link
Author

@shaneqld shaneqld commented Jul 12, 2019

Hi @fenos,

You are correct. My suggestion would be to use a custom serialiser for google.protobuf.Timestamp types. Converting automatically to/from RFC 3339 is performed by Envoy and Cloud Endpoints when transcoding between gRPC and http1/json.

For example, with this simple proto message:

message Project {
  string name = 1;
  google.protobuf.Timestamp create_time = 4;
}

With Envoy or Cloud Endpoints, we receive the following json:

{
  "name": "projects/test-project",
  "create_time": "2014-07-30T10:43:17Z"
}

With BloomRPC, it looks more like:

{
  "name": "Hello",
  "create_time": {
    "seconds": 54646512,
    "nanos": 1235
  }
}

This is not a problem. However, if the purpose of BloomRPC is to allow calling/testing gRPC services using json, then it's worth considering following how others (especially those in the cloud native computing foundation) have implemented serialization.

It's also much simpler writing an RFC 3339 string than manually doing the conversion first or remembering custom syntax.

Just my 2 cents :)

@fenos

This comment has been minimized.

Copy link
Contributor

@fenos fenos commented Jul 23, 2019

@shaneqld this feature is coming soon

@foresx

This comment has been minimized.

Copy link

@foresx foresx commented Jan 19, 2020

any updates news now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.