-
Notifications
You must be signed in to change notification settings - Fork 332
/
tabledump.go
65 lines (58 loc) · 1.34 KB
/
tabledump.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
package command
import (
"errors"
"github.com/didi/sharingan/replayer-agent/utils/protocol/pmysql/common"
"github.com/modern-go/parse"
"github.com/modern-go/parse/model"
)
// TableDumpBody ...
type TableDumpBody struct {
DatabaseLen int
Database string
TableLen int
Table string
}
func (p *TableDumpBody) String() string {
data, err := json.Marshal(p)
if nil != err {
return err.Error()
}
return string(data)
}
// Map ...
func (p *TableDumpBody) Map() model.Map {
r := make(model.Map)
r["database_len"] = p.DatabaseLen
r["database"] = p.Database
r["table_len"] = p.TableLen
r["table"] = p.Table
return r
}
// DecodeTableDumpReq
// doc: https://dev.mysql.com/doc/internals/en/com-table-dump.html
func DecodeTableDumpReq(src *parse.Source) (*TableDumpBody, error) {
common.GetPacketHeader(src)
if src.Error() != nil {
return nil, src.Error()
}
b := src.Read1()
if src.Error() != nil {
return nil, src.Error()
}
if b != 0x13 {
return nil, errors.New("packet isn't table dump query")
}
resp := new(TableDumpBody)
var err error
resp.DatabaseLen, err = common.GetIntN(src.ReadN(1), 1)
if err != nil {
return nil, err
}
resp.Database = common.GetLenencString(src)
resp.TableLen, err = common.GetIntN(src.ReadN(1), 1)
if err != nil {
return nil, err
}
resp.Table = common.GetLenencString(src)
return resp, nil
}