rightEncode encodes integer in a variable-length encoding unambiguously parseable from the end of a string. Used by TupleHash and KMAC.
(d *state, value uint64)
| 84 | // unambiguously parseable from the end of a string. |
| 85 | // Used by TupleHash and KMAC. |
| 86 | func rightEncode(d *state, value uint64) int { |
| 87 | input := d.varintbuf[:] |
| 88 | copy(input, zero[:]) |
| 89 | var offset uint |
| 90 | if value == 0 { |
| 91 | offset = 7 |
| 92 | } else { |
| 93 | binary.BigEndian.PutUint64(input[0:], value) |
| 94 | for offset = 0; offset < 8; offset++ { |
| 95 | if input[offset] != 0 { |
| 96 | break |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | input[8] = byte(8 - offset) |
| 101 | b := input[offset:] |
| 102 | d.Write(b) |
| 103 | return len(b) |
| 104 | } |
| 105 | |
| 106 | // leftEncode encodes integer in a variable-length encoding |
| 107 | // unambiguously parseable from the beginning of a string. |