Skip to content

Commit 2e2193d

Browse files
committed
Merge branch 'master' of github.com:kyleconroy/logical
2 parents 48500c7 + 16bf3af commit 2e2193d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

parse.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ type Relation struct {
129129
Columns []Column
130130
}
131131

132+
type Type struct {
133+
// ID of the data type
134+
ID uint32
135+
Namespace string
136+
Name string
137+
}
138+
132139
type Insert struct {
133140
/// ID of the relation corresponding to the ID in the relation message.
134141
RelationID uint32
@@ -189,7 +196,10 @@ func (Insert) msg() {}
189196
func (Delete) msg() {}
190197
func (Commit) msg() {}
191198
func (Origin) msg() {}
199+
func (Type) msg() {}
192200

201+
// Parse a logical replication message.
202+
// See https://www.postgresql.org/docs/current/static/protocol-logicalrep-message-formats.html
193203
func Parse(src []byte) (Message, error) {
194204
msgType := src[0]
195205
d := &decoder{order: binary.BigEndian, buf: bytes.NewBuffer(src[1:])}
@@ -220,6 +230,12 @@ func Parse(src []byte) (Message, error) {
220230
r.Replica = d.uint8()
221231
r.Columns = d.columns()
222232
return r, nil
233+
case 'Y':
234+
t := Type{}
235+
t.ID = d.uint32()
236+
t.Namespace = d.string()
237+
t.Name = d.string()
238+
return t, nil
223239
case 'I':
224240
i := Insert{}
225241
i.RelationID = d.uint32()
@@ -245,6 +261,6 @@ func Parse(src []byte) (Message, error) {
245261
dl.Row = d.tupledata()
246262
return dl, nil
247263
default:
248-
return nil, fmt.Errorf("Unknown message type for %r", msgType)
264+
return nil, fmt.Errorf("Unknown message type for %s (%d)", []byte{msgType}, msgType)
249265
}
250266
}

parse_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ func TestParseWalData(t *testing.T) {
8888
t.Errorf("val: %s", diff)
8989
}
9090
})
91+
case Type:
92+
if v.ID != 35756 {
93+
t.Errorf("Type OID: %d", v.ID)
94+
}
95+
if v.Namespace != "public" {
96+
t.Errorf("Type namespace: %s", v.Namespace)
97+
}
98+
if v.Name != "ticket_state" {
99+
t.Errorf("Type name: %s", v.Name)
100+
}
91101
}
92102
}
93103
}

testdata/016.waldata

25 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)