MCPcopy Create free account
hub / github.com/chain/txvm / rightEncode

Function rightEncode

crypto/sha3/cshake.go:86–104  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

84// unambiguously parseable from the end of a string.
85// Used by TupleHash and KMAC.
86func 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.

Callers 7

encodeOutputLengthMethod · 0.85
BenchmarkRightEncodeFunction · 0.85
TupleHash128Function · 0.85
TupleHash256Function · 0.85
TupleHashXOF128Function · 0.85
TupleHashXOF256Function · 0.85
encodeOutputLengthMethod · 0.85

Calls 1

WriteMethod · 0.45

Tested by 1

BenchmarkRightEncodeFunction · 0.68