Class: Temporalio::Api::PayloadVisitor

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/api/payload_visitor.rb

Overview

Note:

WARNING: This class is not considered stable for external use and may change as needed for internal reasons.

Visitor for payloads within the protobuf structure. This visitor is thread safe and can be used multiple times since it stores no mutable state.

Instance Method Summary collapse

Constructor Details

#initialize(on_enter: nil, on_exit: nil, skip_search_attributes: false, traverse_any: false) {|value| ... } ⇒ PayloadVisitor

Create a new visitor, calling the block on every Common::V1::Payload or Google::Protobuf::RepeatedField<Payload> encountered.

Parameters:

  • on_enter (Proc, nil) (defaults to: nil)

    Proc called at the beginning of the processing for every protobuf value except the ones calling the block.

  • on_exit (Proc, nil) (defaults to: nil)

    Proc called at the end of the processing for every protobuf value except the ones calling the block.

  • skip_search_attributes (Boolean) (defaults to: false)

    If true, payloads within search attributes do not call the block.

  • traverse_any (Boolean) (defaults to: false)

    If true, when a [Google::Protobuf::Any] is encountered, it is unpacked, visited, then repacked.

Yields:

  • (value)

    Block called with the visited payload value.

Yield Parameters:

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/temporalio/api/payload_visitor.rb', line 28

def initialize(
  on_enter: nil,
  on_exit: nil,
  skip_search_attributes: false,
  traverse_any: false,
  &block
)
  raise ArgumentError, 'Block required' unless block_given?
  @on_enter = on_enter
  @on_exit = on_exit
  @skip_search_attributes = skip_search_attributes
  @traverse_any = traverse_any
  @block = block
end

Instance Method Details

#run(value) ⇒ Object

Visit the given protobuf message.

Parameters:

  • value (Google::Protobuf::Message)

    Message to visit.



46
47
48
49
50
51
# File 'lib/temporalio/api/payload_visitor.rb', line 46

def run(value)
  return unless value.is_a?(Google::Protobuf::MessageExts)
  method_name = method_name_from_proto_name(value.class.descriptor.name)
  send(method_name, value) if respond_to?(method_name, true)
  nil
end