erigon-pulse/turbo/rlphacks/struct.go
Igor Mandrigin adf52465e3
move ./trie to ./turbo/trie (#1114)
Useful for minimizing merge conflicts when rebasing new geth
2020-09-14 11:33:39 +01:00

26 lines
474 B
Go

package rlphacks
func GenerateStructLen(buffer []byte, l int) int {
if l < 56 {
buffer[0] = byte(192 + l)
return 1
}
if l < 256 {
// l can be encoded as 1 byte
buffer[1] = byte(l)
buffer[0] = byte(247 + 1)
return 2
}
if l < 65536 {
buffer[2] = byte(l & 255)
buffer[1] = byte(l >> 8)
buffer[0] = byte(247 + 2)
return 3
}
buffer[3] = byte(l & 255)
buffer[2] = byte((l >> 8) & 255)
buffer[1] = byte(l >> 16)
buffer[0] = byte(247 + 3)
return 4
}