class Temporalio::Converters::PayloadConverter::JSONProtobuf

Encoding for Protobuf values for json/protobuf encoding.

def encoding

(see Encoding.encoding)
def encoding
  ENCODING
end

def from_payload(payload, hint: nil) # rubocop:disable Lint/UnusedMethodArgument

rubocop:disable Lint/UnusedMethodArgument
(see Encoding.from_payload)
def from_payload(payload, hint: nil) # rubocop:disable Lint/UnusedMethodArgument
  type = payload.metadata['messageType']
  # @type var desc: untyped
  desc = Google::Protobuf::DescriptorPool.generated_pool.lookup(type)
  raise "No protobuf message found in global pool for message type #{type}" unless desc
  desc.msgclass.decode_json(payload.data)
end

def to_payload(value, hint: nil) # rubocop:disable Lint/UnusedMethodArgument

rubocop:disable Lint/UnusedMethodArgument
(see Encoding.to_payload)
def to_payload(value, hint: nil) # rubocop:disable Lint/UnusedMethodArgument
  return nil unless value.is_a?(Google::Protobuf::MessageExts)
  Api::Common::V1::Payload.new(
    metadata: { 'encoding' => ENCODING, 'messageType' => value.class.descriptor.name },
    data: value.to_json
  )
end