Class: Temporalio::Converters::PayloadConverter::BinaryPlain
- Defined in:
- lib/temporalio/converters/payload_converter/binary_plain.rb
Overview
Encoding for ASCII_8BIT
string values for binary/plain
encoding.
Constant Summary collapse
- ENCODING =
'binary/plain'
Instance Method Summary collapse
-
#encoding ⇒ String
Encoding that will be put on the payload metadata if this encoding converter can handle the value.
-
#from_payload(payload) ⇒ Object
Convert the payload to a Ruby value.
-
#to_payload(value) ⇒ Api::Common::V1::Payload?
Convert value to payload if this encoding converter can handle it, or return
nil
.
Instance Method Details
#encoding ⇒ String
Returns Encoding that will be put on the payload metadata if this encoding converter can handle the value.
14 15 16 |
# File 'lib/temporalio/converters/payload_converter/binary_plain.rb', line 14 def encoding ENCODING end |
#from_payload(payload) ⇒ Object
Convert the payload to a Ruby value. The caller confirms the encoding
metadata matches #encoding, so this will error if it cannot convert.
29 30 31 |
# File 'lib/temporalio/converters/payload_converter/binary_plain.rb', line 29 def from_payload(payload) payload.data end |
#to_payload(value) ⇒ Api::Common::V1::Payload?
Convert value to payload if this encoding converter can handle it, or return nil
. If the converter can handle it, the resulting payload must have encoding
metadata on the payload set to the value of #encoding.
19 20 21 22 23 24 25 26 |
# File 'lib/temporalio/converters/payload_converter/binary_plain.rb', line 19 def to_payload(value) return nil unless value.is_a?(String) && value.encoding == ::Encoding::ASCII_8BIT Temporalio::Api::Common::V1::Payload.new( metadata: { 'encoding' => ENCODING }, data: value ) end |