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, hint: nil) ⇒ Object
Convert a payload to a Ruby value.
-
#from_payloads(payloads, hints: nil) ⇒ Array<Object>
Convert a payload set to Ruby values.
-
#to_payload(value, hint: nil) ⇒ Api::Common::V1::Payload
Convert a Ruby value to a payload.
-
#to_payloads(values, hints: nil) ⇒ 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 |
# File 'lib/temporalio/converters/payload_converter.rb', line 24 def self.new_with_defaults(json_parse_options: { create_additions: true }, json_generate_options: {}) 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, hint: nil) ⇒ Object
Convert a payload to a Ruby value.
62 63 64 |
# File 'lib/temporalio/converters/payload_converter.rb', line 62 def from_payload(payload, hint: nil) raise NotImplementedError end |
#from_payloads(payloads, hints: nil) ⇒ Array<Object>
Convert a payload set to Ruby values.
74 75 76 77 78 |
# File 'lib/temporalio/converters/payload_converter.rb', line 74 def from_payloads(payloads, hints: nil) return [] unless payloads payloads.payloads.zip(Array(hints)).map { |payload, hint| from_payload(payload, hint:) } end |
#to_payload(value, hint: nil) ⇒ Api::Common::V1::Payload
Convert a Ruby value to a payload.
39 40 41 |
# File 'lib/temporalio/converters/payload_converter.rb', line 39 def to_payload(value, hint: nil) raise NotImplementedError end |
#to_payloads(values, hints: nil) ⇒ Api::Common::V1::Payloads
Convert multiple Ruby values to a payload set.
51 52 53 54 55 |
# File 'lib/temporalio/converters/payload_converter.rb', line 51 def to_payloads(values, hints: nil) Api::Common::V1::Payloads.new( payloads: Array(values).zip(Array(hints)).map { |value, hint| to_payload(value, hint:) } ) end |