-
Notifications
You must be signed in to change notification settings - Fork 107
Adding payload codec pipeline #224
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
Changes from all commits
d8a5df7
06626ad
ac66062
0aec214
50ab4da
be0510c
bbc6d89
73120be
22006e3
6e9624e
55253af
399f9b8
b461af9
c76042a
7310062
256f472
9c776c5
3c5b77a
dc74dae
51f6c9b
a280807
7290de3
68de5bf
acd5220
62137ba
0bc8a62
391cd1f
a16f856
36b45a6
a7ca88a
71b5bd3
7285165
2842f6f
265cd3e
aca915b
1b03601
c9af317
1c4177f
9a7d969
10d7cd6
3b21b3d
368afe3
e23dc5e
60b09d3
c3efa7f
2e50ab5
086a635
9297afb
622b8bc
521e53e
b9acc5d
fedfd7f
54be471
92a4db3
ebc8462
9bab13b
91c50c9
cb02791
4516126
1b78814
f5978d2
f0801b2
8a4d875
7e223f0
79ecd67
1c0e38c
47e04fd
557912a
b76c17d
a9b236f
4f0684b
19fae32
3d1df21
c698f70
1ca8365
c49aadb
04cd6df
e45bbef
7170411
33208a7
4c03bf7
ea8a78a
1e59a14
961ed83
1a7dbac
ac589fd
525fa0b
7a7648b
4012392
151eb75
064d2ee
4537fda
ddae0f9
c3e662b
8c25716
decf50a
0da1591
409eb83
b61298e
f48893f
eb6618d
173f3b4
3057ac5
84b3833
5c96eb5
e7a3dc0
eff84f1
56e2e17
5b0d0ab
b907446
016cab4
350720d
c83746c
2008444
8fa91a7
d1140c3
946eb98
8cc93aa
4c19e3e
d08b3d9
fda7801
5c96811
3524880
1682222
8e64342
9a8ed7c
47ef88b
66d643e
b199a36
599904c
9d9d462
0a4739d
c26eeb2
bf78dbd
b36d27c
24be2fd
45765e0
37b0b73
c3f1fbd
3fbcbe5
7d2ef3a
fa8fec0
e5d4efe
c75bda4
4896f84
7aff9f3
afca5da
dd6d544
9968901
f3925d4
ecd87ee
adb48dd
a6557c2
7560963
c1457c0
76ee0ba
1c18b5d
20b54bb
ee37874
33ed56d
7d28754
22420b7
61a95e7
85c6bae
74a29c8
70efdb4
88eb156
000f3e3
4d11b85
1266923
1edc8b4
ee81e0c
3deda64
e59db77
e805a38
a57601a
1b270af
48cbe20
0e2cbae
d768b67
41d8c7d
31d9fe7
0dba46a
2efdbf9
4b95576
03b6f51
daaa508
14411ca
281fdec
353c9d6
40f1aa4
f9b38b7
361dd0d
0696eab
51fbeb9
5d492a1
71c85e9
97aab20
5f1f868
1693693
0376b62
e98745b
8b81871
b9be213
35db489
d90d162
0a2f176
c357bc4
82771d8
f49e14e
0f497f6
706a49d
6ccbb4a
66d0021
9ef86bd
900e52c
7dce335
f4b916f
957c0c5
837d5b4
ec831fc
43040a8
dee6e30
713d770
94cd205
c913539
0c86fbf
015bc07
153a877
08e4ef1
bf3be07
9ef5d82
2cd974e
154a068
77ab242
6297ac0
58e17da
5f2e396
9e8fadb
47556d8
8eaf5e7
cea8ad2
9eec6af
d8a42d8
145290c
6ca7458
1d90708
2d6a92b
5f02284
1aa6ba1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,19 @@ module Temporal | |
| module Concerns | ||
| module Payloads | ||
| def from_payloads(payloads) | ||
| payloads = payload_codec.decodes(payloads) | ||
| payload_converter.from_payloads(payloads) | ||
| end | ||
|
|
||
| def from_payload(payload) | ||
| payload = payload_codec.decode(payload) | ||
| payload_converter.from_payload(payload) | ||
| end | ||
|
|
||
| def from_payload_map_without_codec(payload_map) | ||
| payload_map.map { |key, value| [key, payload_converter.from_payload(value)] }.to_h | ||
| end | ||
|
|
||
| def from_result_payloads(payloads) | ||
| from_payloads(payloads)&.first | ||
| end | ||
|
|
@@ -30,11 +36,20 @@ def from_payload_map(payload_map) | |
| end | ||
|
|
||
| def to_payloads(data) | ||
| payload_converter.to_payloads(data) | ||
| payloads = payload_converter.to_payloads(data) | ||
| payload_codec.encodes(payloads) | ||
| end | ||
|
|
||
| def to_payload(data) | ||
| payload_converter.to_payload(data) | ||
| payload = payload_converter.to_payload(data) | ||
| payload_codec.encode(payload) | ||
| end | ||
|
|
||
| def to_payload_map_without_codec(data) | ||
| # skips the payload_codec step because search attributes don't use this pipeline | ||
| data.transform_values do |value| | ||
| payload_converter.to_payload(value) | ||
| end | ||
| end | ||
|
|
||
| def to_result_payloads(data) | ||
|
|
@@ -62,6 +77,10 @@ def to_payload_map(data) | |
| def payload_converter | ||
| Temporal.configuration.converter | ||
| end | ||
|
|
||
| def payload_codec | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment at the top of this file or on this method explaining the difference between payload converters and payload codecs would be worthwhile. Or actually probably in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added to the |
||
| Temporal.configuration.payload_codec | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| module Temporal | ||
| module Connection | ||
| module Converter | ||
| module Codec | ||
| class Base | ||
| def encodes(payloads) | ||
| return nil if payloads.nil? | ||
|
|
||
| Temporalio::Api::Common::V1::Payloads.new( | ||
| payloads: payloads.payloads.map(&method(:encode)) | ||
| ) | ||
| end | ||
|
|
||
| def decodes(payloads) | ||
| return nil if payloads.nil? | ||
|
|
||
| Temporalio::Api::Common::V1::Payloads.new( | ||
| payloads: payloads.payloads.map(&method(:decode)) | ||
| ) | ||
| end | ||
|
Comment on lines
+6
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would these be overridden by someone extending this class? Why not move these into
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they can be, I just was following the same pattern as in You probably are going to only override |
||
|
|
||
| def encode(payload) | ||
| # should return Temporalio::Api::Common::V1::Payload | ||
| raise NotImplementedError, 'codec converter needs to implement encode' | ||
| end | ||
|
|
||
| def decode(payload) | ||
| # should return Temporalio::Api::Common::V1::Payload | ||
| raise NotImplementedError, 'codec converter needs to implement decode' | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||
| require 'temporal/connection/converter/codec/base' | ||||
|
|
||||
| module Temporal | ||||
| module Connection | ||||
| module Converter | ||||
| module Codec | ||||
| # Performs encoding/decoding on the payloads via the given payload codecs. When encoding | ||||
| # the codecs are applied last to first meaning the earlier encodings wrap the later ones. | ||||
| # When decoding, the codecs are applied first to last to reverse the effect. | ||||
| class Chain < Base | ||||
| def initialize(payload_codecs:) | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This might be more ergonomic with a splat or non-keyword argument instead
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i agree, i was just keeping the same pattern as
|
||||
| @payload_codecs = payload_codecs | ||||
| end | ||||
|
|
||||
| def encode(payload) | ||||
| payload_codecs.reverse_each do |payload_codec| | ||||
| payload = payload_codec.encode(payload) | ||||
| end | ||||
| payload | ||||
| end | ||||
|
|
||||
| def decode(payload) | ||||
| payload_codecs.each do |payload_codec| | ||||
| payload = payload_codec.decode(payload) | ||||
| end | ||||
| payload | ||||
| end | ||||
|
|
||||
| private | ||||
|
|
||||
| attr_reader :payload_codecs | ||||
| end | ||||
| end | ||||
| end | ||||
| end | ||||
| 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.
The abstraction is seeping through here a bit. Should this be named something like
from_payload_map_without_codec? The call on search attributes would then be made outside of this file which is specific to performing various kinds of encoding.