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

Function LengthEncodedInt

IceFireDB-SQLProxy/pkg/mysql/mysql/util.go:143–171  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

141}
142
143func LengthEncodedInt(b []byte) (num uint64, isNull bool, n int) {
144 if len(b) == 0 {
145 return 0, true, 0
146 }
147
148 switch b[0] {
149 // 251: NULL
150 case 0xfb:
151 return 0, true, 1
152
153 // 252: value of following 2
154 case 0xfc:
155 return uint64(b[1]) | uint64(b[2])<<8, false, 3
156
157 // 253: value of following 3
158 case 0xfd:
159 return uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16, false, 4
160
161 // 254: value of following 8
162 case 0xfe:
163 return uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16 |
164 uint64(b[4])<<24 | uint64(b[5])<<32 | uint64(b[6])<<40 |
165 uint64(b[7])<<48 | uint64(b[8])<<56,
166 false, 9
167 }
168
169 // 0-250: value of first byte
170 return uint64(b[0]), false, 1
171}
172
173func PutLengthEncodedInt(n uint64) []byte {
174 switch {

Callers 9

TestMysqlNullDecodeMethod · 0.70
TestMysqlEmptyDecodeMethod · 0.70
ParseBinaryMethod · 0.70
LengthEncodedStringFunction · 0.70
SkipLengthEncodedStringFunction · 0.70
ParseMethod · 0.70
handleOKPacketMethod · 0.50
readResultsetMethod · 0.50

Calls

no outgoing calls

Tested by 2

TestMysqlNullDecodeMethod · 0.56
TestMysqlEmptyDecodeMethod · 0.56