Skip to content

Commit 085c631

Browse files
committed
Change field ID to uint8
1 parent a45d879 commit 085c631

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

serialization/serialization.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
type Message struct {
1919
Version uint8 // >= 0
2020
Format Format
21-
fieldIndex map[string]int
21+
fieldIndex map[string]uint8
2222
}
2323

2424
func (m *Message) String() (text string) {
@@ -59,7 +59,7 @@ func (f *Format) String() (text string) {
5959

6060
// Field represents a `message_field`
6161
type Field struct {
62-
ID int
62+
ID uint8
6363
Type FieldType
6464
Optional bool
6565
Name string
@@ -199,7 +199,7 @@ func Unmarshal(data []byte, v interface{}) error {
199199
return err
200200
}
201201
if m.fieldIndex == nil {
202-
m.fieldIndex = make(map[string]int, len(m.Format.Fields))
202+
m.fieldIndex = make(map[string]uint8, len(m.Format.Fields))
203203
}
204204
for _, field := range m.Format.Fields {
205205
m.fieldIndex[field.Name] = field.ID
@@ -215,11 +215,11 @@ func Unmarshal(data []byte, v interface{}) error {
215215
if int(pos)+1 > len(data) || int(data[pos]>>1) != i {
216216
// The field number we got doesn't match what we expect,
217217
// so a field was skipped.
218-
m.Fields[i].ID = i
218+
m.Fields[i].ID = uint8(i)
219219
m.Fields[i].Skipped = true
220220
continue
221221
}
222-
m.Fields[i].ID = int(data[pos] >> 1)
222+
m.Fields[i].ID = uint8(data[pos] >> 1)
223223
pos++
224224
var n uint64
225225
var err error

serialization/serialization_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func TestUmarshal_event1(t *testing.T) {
386386
},
387387
},
388388
},
389-
fieldIndex: map[string]int{
389+
fieldIndex: map[string]uint8{
390390
"gtid_flags": 0,
391391
"uuid": 1,
392392
"gno": 2,
@@ -413,5 +413,5 @@ func TestUmarshal_event1(t *testing.T) {
413413

414414
sv, err := msg.GetFieldByName("immediate_server_version")
415415
require.NoError(t, err)
416-
require.Equal(t, 9, sv.ID)
416+
require.Equal(t, uint8(9), sv.ID)
417417
}

0 commit comments

Comments
 (0)