MCPcopy
hub / github.com/go-sql-driver/mysql / readLengthEncodedInteger

Function readLengthEncodedInteger

utils.go:565–591  ·  view source on GitHub ↗

returns the number read, whether the value is NULL and the number of bytes read

(b []byte)

Source from the content-addressed store, hash-verified

563
564// returns the number read, whether the value is NULL and the number of bytes read
565func readLengthEncodedInteger(b []byte) (uint64, bool, int) {
566 // See issue #349
567 if len(b) == 0 {
568 return 0, true, 1
569 }
570
571 switch b[0] {
572 // 251: NULL
573 case 0xfb:
574 return 0, true, 1
575
576 // 252: value of following 2
577 case 0xfc:
578 return uint64(binary.LittleEndian.Uint16(b[1:])), false, 3
579
580 // 253: value of following 3
581 case 0xfd:
582 return uint64(getUint24(b[1:])), false, 4
583
584 // 254: value of following 8
585 case 0xfe:
586 return uint64(binary.LittleEndian.Uint64(b[1:])), false, 9
587 }
588
589 // 0-250: value of first byte
590 return uint64(b[0]), false, 1
591}
592
593// encodes a uint64 value and appends it to the given bytes slice
594func appendLengthEncodedInteger(b []byte, n uint64) []byte {

Callers 8

TestLengthEncodedIntegerFunction · 0.85
handleOkPacketMethod · 0.85
readRowMethod · 0.85
skipRowsMethod · 0.85
readRowMethod · 0.85
readLengthEncodedStringFunction · 0.85
skipLengthEncodedStringFunction · 0.85

Calls 1

getUint24Function · 0.85

Tested by 1

TestLengthEncodedIntegerFunction · 0.68