35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/pg/replication/pg_output.rb', line 35
def self.read_message(buffer)
case buffer.read_char
in "B"
PGOutput::Begin.new(
final_lsn: buffer.read_int64,
timestamp: buffer.read_timestamp,
xid: buffer.read_int32,
)
in "M"
PGOutput::Message.new(
transactional: buffer.read_bool,
lsn: buffer.read_int64,
prefix: buffer.read_cstring,
content: case buffer.read_int32
in 0
nil
in n
buffer.read(n)
end,
)
in "C"
buffer.read_int8 PGOutput::Commit.new(
lsn: buffer.read_int64,
end_lsn: buffer.read_int64,
timestamp: buffer.read_timestamp,
)
in "O"
PGOutput::Origin.new(
commit_lsn: buffer.read_int64,
name: buffer.read_cstring,
)
in "R"
PGOutput::Relation.new(
oid: buffer.read_int32,
namespace: buffer.read_cstring.then { |ns| ns == "" ? "pg_catalog" : ns },
name: buffer.read_cstring,
replica_identity: buffer.read_char,
columns: buffer.read_int16.times.map do
PGOutput::Column.new(
flags: buffer.read_int8,
name: buffer.read_cstring,
oid: buffer.read_int32,
modifier: buffer.read_int32,
)
end
)
in "Y"
PGOutput::Type.new(
oid: buffer.read_int32,
namespace: buffer.read_cstring,
name: buffer.read_cstring,
)
in "I"
PGOutput::Insert.new(
oid: buffer.read_int32,
new: case a = buffer.read_char
when "N"
PGOutput.read_tuples(buffer)
else
[]
end,
)
in "U"
oid = buffer.read_int32
key = []
new = []
old = []
until buffer.eof?
case buffer.read_char
when "K"
key = PGOutput.read_tuples(buffer)
when "N"
new = PGOutput.read_tuples(buffer)
when "O"
old = PGOutput.read_tuples(buffer)
end
end
PGOutput::Update.new(
oid:,
key:,
old:,
new:,
)
in "D"
oid = buffer.read_int32
key = []
old = []
until buffer.eof?
case buffer.read_char
when "K"
key = PGOutput.read_tuples(buffer)
when "O"
old = PGOutput.read_tuples(buffer)
end
end
PGOutput::Delete.new(
oid:,
key:,
old:,
)
in "T"
PGOutput::Truncate.new(
oid: buffer.read_int32,
data: buffer.buffer,
)
in unknown
raise "Unknown PGOutput message type: #{unknown}"
end
end
|