returns the number read, whether the value is NULL and the number of bytes read
(b []byte)
| 563 | |
| 564 | // returns the number read, whether the value is NULL and the number of bytes read |
| 565 | func 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 |
| 594 | func appendLengthEncodedInteger(b []byte, n uint64) []byte { |