-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.go
50 lines (40 loc) · 1.01 KB
/
mysql.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
package main
import (
"fmt"
)
func peakLenStr(data []byte) (string, int) {
var idx int
return parseLenStr(&idx, data), idx
}
func parseLenStr(idx *int, data []byte) string {
size := int(data[*idx])
*idx += 1
str := string(data[*idx : *idx+size])
*idx += size
return str
}
func parseColumnDef(data []byte) {
var idx int
// catelog
catelog := parseLenStr(&idx, data)
schema := parseLenStr(&idx, data)
table := parseLenStr(&idx, data)
org_table := parseLenStr(&idx, data)
name := parseLenStr(&idx, data)
org_name := parseLenStr(&idx, data)
fmt.Println(" catelog:", catelog)
fmt.Println(" schema:", schema)
fmt.Println(" table:", table)
fmt.Println(" org_table:", org_table)
fmt.Println(" name:", name)
fmt.Println(" org_name:", org_name)
}
func readPacket(data []byte) []byte {
// Read packet header
hdr := data[:4]
// Packet Length [24 bit]
pktLen := int(uint32(hdr[0]) | uint32(hdr[1])<<8 | uint32(hdr[2])<<16)
// Read packet body [pktLen bytes]
payload := data[4 : 4+pktLen]
return payload
}