-
Notifications
You must be signed in to change notification settings - Fork 107
Adds ProtoJSON support for protobuf inputs #192
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
Conversation
| module Converter | ||
| module Payload | ||
| class ProtoJSON | ||
| class InvalidPayload < RuntimeError; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like this is used anywhere. Should we add error handling as mentioned in the TODO? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d'oh ya was going to add handling, but then noticed the JSON deserializer didn't have anything explicit so didn't follow up. removed the error class.
| end | ||
|
|
||
| def to_payload(data) | ||
| return unless data&.is_a?(Google::Protobuf::MessageExts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need for &. since is_a? is defined on a NilClass as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
| @@ -0,0 +1,22 @@ | |||
| require 'temporal/connection/converter/payload/json' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a wrong require, you need proto_json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d'oh Done
| it 'converts' do | ||
| input = Temporal::Api::Common::V1::Payload.new( | ||
| metadata: { 'hello' => 'world' }, | ||
| data: 'hello world', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This data type won't get picked by the target converter, right? It's not a subclass of Google::Protobuf::MessageExts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment. using Temporal::Api::Common::V1::Payload as the input given it's an available proto message. to_payload wraps it, so the result data is the json'd input w/ the metadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, makes sense. It might be a bit clearer if you were to pick a proto that has nothing to do with payloads. But the comment solves this issue
stuppy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
| module Converter | ||
| module Payload | ||
| class ProtoJSON | ||
| class InvalidPayload < RuntimeError; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d'oh ya was going to add handling, but then noticed the JSON deserializer didn't have anything explicit so didn't follow up. removed the error class.
| end | ||
|
|
||
| def to_payload(data) | ||
| return unless data&.is_a?(Google::Protobuf::MessageExts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
| @@ -0,0 +1,22 @@ | |||
| require 'temporal/connection/converter/payload/json' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d'oh Done
| it 'converts' do | ||
| input = Temporal::Api::Common::V1::Payload.new( | ||
| metadata: { 'hello' => 'world' }, | ||
| data: 'hello world', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment. using Temporal::Api::Common::V1::Payload as the input given it's an available proto message. to_payload wraps it, so the result data is the json'd input w/ the metadata
antstorm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you for the PR
| it 'converts' do | ||
| input = Temporal::Api::Common::V1::Payload.new( | ||
| metadata: { 'hello' => 'world' }, | ||
| data: 'hello world', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, makes sense. It might be a bit clearer if you were to pick a proto that has nothing to do with payloads. But the comment solves this issue
#191