MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / ParseBinary

Method ParseBinary

IceFireDB-SQLProxy/pkg/mysql/mysql/rowdata.go:81–260  ·  view source on GitHub ↗

ParseBinary parses the binary format of data see https://dev.mysql.com/doc/internals/en/binary-protocol-value.html

(f []*Field, dst []FieldValue)

Source from the content-addressed store, hash-verified

79// ParseBinary parses the binary format of data
80// see https://dev.mysql.com/doc/internals/en/binary-protocol-value.html
81func (p RowData) ParseBinary(f []*Field, dst []FieldValue) ([]FieldValue, error) {
82 for len(dst) < len(f) {
83 dst = append(dst, FieldValue{})
84 }
85 data := dst[:len(f)]
86
87 if p[0] != OK_HEADER {
88 return nil, ErrMalformPacket
89 }
90
91 pos := 1 + ((len(f) + 7 + 2) >> 3)
92
93 nullBitmap := p[1:pos]
94
95 var isNull bool
96 var n int
97 var err error
98 var v []byte
99 for i := range data {
100 if nullBitmap[(i+2)/8]&(1<<(uint(i+2)%8)) > 0 {
101 data[i].Type = FieldValueTypeNull
102 continue
103 }
104
105 isUnsigned := f[i].Flag&UNSIGNED_FLAG != 0
106
107 switch f[i].Type {
108 case MYSQL_TYPE_NULL:
109 data[i].Type = FieldValueTypeNull
110 continue
111
112 case MYSQL_TYPE_TINY:
113 if isUnsigned {
114 v := ParseBinaryUint8(p[pos : pos+1])
115 data[i].Type = FieldValueTypeUnsigned
116 data[i].value = uint64(v)
117 } else {
118 v := ParseBinaryInt8(p[pos : pos+1])
119 data[i].Type = FieldValueTypeSigned
120 data[i].value = utils.Int64ToUint64(int64(v))
121 }
122 pos++
123 continue
124
125 case MYSQL_TYPE_SHORT, MYSQL_TYPE_YEAR:
126 if isUnsigned {
127 v := ParseBinaryUint16(p[pos : pos+2])
128 data[i].Type = FieldValueTypeUnsigned
129 data[i].value = uint64(v)
130 } else {
131 v := ParseBinaryInt16(p[pos : pos+2])
132 data[i].Type = FieldValueTypeSigned
133 data[i].value = utils.Int64ToUint64(int64(v))
134 }
135 pos += 2
136 continue
137
138 case MYSQL_TYPE_INT24, MYSQL_TYPE_LONG:

Callers 1

ParseMethod · 0.95

Calls 15

Int64ToUint64Function · 0.92
Float64ToUint64Function · 0.92
ParseBinaryUint8Function · 0.70
ParseBinaryInt8Function · 0.70
ParseBinaryUint16Function · 0.70
ParseBinaryInt16Function · 0.70
ParseBinaryUint32Function · 0.70
ParseBinaryInt32Function · 0.70
ParseBinaryUint64Function · 0.70
ParseBinaryInt64Function · 0.70
ParseBinaryFloat32Function · 0.70
ParseBinaryFloat64Function · 0.70

Tested by

no test coverage detected