AppendLengthEncodedInteger: encodes a uint64 value and appends it to the given bytes slice
(b []byte, n uint64)
| 91 | |
| 92 | // AppendLengthEncodedInteger: encodes a uint64 value and appends it to the given bytes slice |
| 93 | func AppendLengthEncodedInteger(b []byte, n uint64) []byte { |
| 94 | switch { |
| 95 | case n <= 250: |
| 96 | return append(b, byte(n)) |
| 97 | |
| 98 | case n <= 0xffff: |
| 99 | return append(b, 0xfc, byte(n), byte(n>>8)) |
| 100 | |
| 101 | case n <= 0xffffff: |
| 102 | return append(b, 0xfd, byte(n), byte(n>>8), byte(n>>16)) |
| 103 | } |
| 104 | return append(b, 0xfe, byte(n), byte(n>>8), byte(n>>16), byte(n>>24), |
| 105 | byte(n>>32), byte(n>>40), byte(n>>48), byte(n>>56)) |
| 106 | } |
| 107 | |
| 108 | func RandomBuf(size int) ([]byte, error) { |
| 109 | buf := make([]byte, size) |