encodes a uint64 value and appends it to the given bytes slice
(b []byte, n uint64)
| 592 | |
| 593 | // encodes a uint64 value and appends it to the given bytes slice |
| 594 | func appendLengthEncodedInteger(b []byte, n uint64) []byte { |
| 595 | switch { |
| 596 | case n <= 250: |
| 597 | return append(b, byte(n)) |
| 598 | |
| 599 | case n <= 0xffff: |
| 600 | b = append(b, 0xfc) |
| 601 | return binary.LittleEndian.AppendUint16(b, uint16(n)) |
| 602 | |
| 603 | case n <= 0xffffff: |
| 604 | return append(b, 0xfd, byte(n), byte(n>>8), byte(n>>16)) |
| 605 | } |
| 606 | b = append(b, 0xfe) |
| 607 | return binary.LittleEndian.AppendUint64(b, n) |
| 608 | } |
| 609 | |
| 610 | func appendLengthEncodedString(b []byte, s string) []byte { |
| 611 | b = appendLengthEncodedInteger(b, uint64(len(s))) |
no outgoing calls