Class: Temporalio::Converters::PayloadConverter

Inherits:
Object
  • Object
show all
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

Composite

Defined Under Namespace

Classes: BinaryNull, BinaryPlain, BinaryProtobuf, Composite, Encoding, JSONPlain, JSONProtobuf

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultPayloadConverter::Composite

Returns Default payload converter.

Returns:



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.

Parameters:

  • json_parse_options (Hash) (defaults to: { create_additions: true })

    Options for JSON.parse.

  • json_generate_options (Hash) (defaults to: {})

    Options for JSON.generate.

Returns:



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: json_parse_options, generate_options: json_generate_options)
    )
  )
end

Instance Method Details

#from_payload(payload) ⇒ Object

Convert a payload to a Ruby value.

Parameters:

Returns:

  • (Object)

    Converted Ruby value.

Raises:

  • (NotImplementedError)


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.

Parameters:

Returns:

  • (Array<Object>)

    Converted 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.

Parameters:

  • value (Object)

    Ruby value.

Returns:

Raises:

  • (NotImplementedError)


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.

Parameters:

  • values (Object)

    Ruby values, converted to array via Array.

Returns:



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