forked from didi/sharingan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.go
57 lines (48 loc) · 1.05 KB
/
reset.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
package prepared
import (
"errors"
"github.com/light-pan/sharingan/replayer-agent/utils/protocol/pmysql/common"
"github.com/modern-go/parse"
"github.com/modern-go/parse/model"
)
// ResetBody ...
type ResetBody struct {
StatementID int
}
func (p *ResetBody) String() string {
data, err := json.Marshal(p)
if nil != err {
return err.Error()
}
return string(data)
}
// Map ...
func (p *ResetBody) Map() model.Map {
r := make(model.Map)
r["statement_id"] = p.StatementID
return r
}
// DecodeStmtReset ...
func DecodeStmtReset(src *parse.Source) (*ResetBody, error) {
pkLen, _ := common.GetPacketHeader(src)
if src.Error() != nil {
return nil, src.Error()
}
if pkLen != 0x05 {
return nil, errors.New("packet isn't reset prepared query")
}
b := src.Read1()
if src.Error() != nil {
return nil, src.Error()
}
if b != 0x1a {
return nil, errors.New("packet isn't reset prepared query")
}
resp := new(ResetBody)
var err error
resp.StatementID, err = common.GetIntN(src.ReadN(4), 4)
if nil != err {
return nil, err
}
return resp, nil
}