Class: Temporalio::Converters::PayloadConverter
- Inherits:
-
Object
- Object
- Temporalio::Converters::PayloadConverter
- Defined in:
- lib/temporalio/converters/payload_converter.rb,
lib/temporalio/converters/payload_converter/encoding.rb,
lib/temporalio/converters/payload_converter/composite.rb,
lib/temporalio/converters/payload_converter/json_plain.rb,
lib/temporalio/converters/payload_converter/binary_null.rb,
lib/temporalio/converters/payload_converter/binary_plain.rb,
lib/temporalio/converters/payload_converter/json_protobuf.rb,
lib/temporalio/converters/payload_converter/binary_protobuf.rb
Overview
Base class for converting Ruby values to/from Temporal payloads.
Direct Known Subclasses
Defined Under Namespace
Classes: BinaryNull, BinaryPlain, BinaryProtobuf, Composite, Encoding, JSONPlain, JSONProtobuf
Class Method Summary collapse
-
.default ⇒ PayloadConverter::Composite
Default payload converter.
-
.new_with_defaults(json_parse_options: { create_additions: true }, json_generate_options: {}) ⇒ PayloadConverter::Composite
Create a new payload converter with the default set of encoding converters.
Instance Method Summary collapse
-
#from_payload(payload) ⇒ Object
Convert a payload to a Ruby value.
-
#from_payloads(payloads) ⇒ Array<Object>
Convert a payload set to Ruby values.
-
#to_payload(value) ⇒ Api::Common::V1::Payload
Convert a Ruby value to a payload.
-
#to_payloads(values) ⇒ Api::Common::V1::Payloads
Convert multiple Ruby values to a payload set.
Class Method Details
.default ⇒ PayloadConverter::Composite
Returns Default payload converter.
15 16 17 |
# File 'lib/temporalio/converters/payload_converter.rb', line 15 def self.default @default ||= new_with_defaults end |
.new_with_defaults(json_parse_options: { create_additions: true }, json_generate_options: {}) ⇒ PayloadConverter::Composite
Create a new payload converter with the default set of encoding converters.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/temporalio/converters/payload_converter.rb', line 24 def self.new_with_defaults(json_parse_options: { create_additions: true }, json_generate_options: {}) Ractor.make_shareable( PayloadConverter::Composite.new( PayloadConverter::BinaryNull.new, PayloadConverter::BinaryPlain.new, PayloadConverter::JSONProtobuf.new, PayloadConverter::BinaryProtobuf.new, PayloadConverter::JSONPlain.new(parse_options: , generate_options: ) ) ) end |
Instance Method Details
#from_payload(payload) ⇒ Object
Convert a payload to a Ruby value.
58 59 60 |
# File 'lib/temporalio/converters/payload_converter.rb', line 58 def from_payload(payload) raise NotImplementedError end |
#from_payloads(payloads) ⇒ Array<Object>
Convert a payload set to Ruby values.
66 67 68 69 70 |
# File 'lib/temporalio/converters/payload_converter.rb', line 66 def from_payloads(payloads) return [] unless payloads payloads.payloads.map { |payload| from_payload(payload) } end |
#to_payload(value) ⇒ Api::Common::V1::Payload
Convert a Ruby value to a payload.
40 41 42 |
# File 'lib/temporalio/converters/payload_converter.rb', line 40 def to_payload(value) raise NotImplementedError end |
#to_payloads(values) ⇒ Api::Common::V1::Payloads
Convert multiple Ruby values to a payload set.
48 49 50 51 52 |
# File 'lib/temporalio/converters/payload_converter.rb', line 48 def to_payloads(values) Api::Common::V1::Payloads.new( payloads: Array(values).map { |value| to_payload(value) } ) end |