Class: Pgoutput::BinaryParser

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

Overview

Offset-based binary parser for one PostgreSQL pgoutput logical replication message payload.

A parser instance is intentionally short-lived and mutable while reading a single payload. Its returned message object is deeply frozen/shareable and may cross Ractor boundaries safely.

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ void

Parameters:

  • payload (String)

    one pgoutput message payload from a CopyData frame.



15
16
17
18
# File 'lib/pgoutput/binary_parser.rb', line 15

def initialize(payload)
  @payload = payload.b
  @offset = 0
end

Instance Method Details

#parsePgoutput::Messages::Begin, ...

Parse one supported pgoutput message.

Supported MVP tags are ‘B`, `R`, `I`, `U`, `D`, and `C`.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pgoutput/binary_parser.rb', line 29

def parse
  case read_byte_chr
  when "B" then parse_begin
  when "R" then parse_relation
  when "I" then parse_insert
  when "U" then parse_update
  when "D" then parse_delete
  when "C" then parse_commit
  else
    raise UnsupportedMessageError, "unsupported pgoutput message tag"
  end
end