Class: Pgoutput::Decoder::ValueDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/pgoutput/decoder/value_decoder.rb

Overview

Decodes one pgoutput-parser TupleValue using a TypeRegistry.

Instance Method Summary collapse

Constructor Details

#initialize(type_registry: TypeRegistry.default) ⇒ void

Parameters:

  • type_registry (TypeRegistry) (defaults to: TypeRegistry.default)


11
12
13
14
# File 'lib/pgoutput/decoder/value_decoder.rb', line 11

def initialize(type_registry: TypeRegistry.default)
  @type_registry = type_registry
  freeze
end

Instance Method Details

#decode(tuple_value) ⇒ Object, ...

Decode one tuple value.

Parameters:

  • tuple_value (Pgoutput::Messages::TupleValue)

Returns:

  • (Object, nil, Symbol)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pgoutput/decoder/value_decoder.rb', line 20

def decode(tuple_value)
  case tuple_value.format
  when :null
    nil
  when :unchanged_toast
    :unchanged_toast
  when :text, :binary
    @type_registry.decode(tuple_value.oid, tuple_value.raw, tuple_value.format)
  else
    raise ValueDecodeError, "unsupported tuple value format: #{tuple_value.format.inspect}"
  end
end