mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 02:31:19 +00:00
0893821e35
* disable conditional go 1.20 code until we upgrade * bazel decided this was unreachable and removed it! --------- Co-authored-by: kasey <kasey@users.noreply.github.com>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
//go:build !prysmAt1.20
|
|
// +build !prysmAt1.20
|
|
|
|
package bytesutil
|
|
|
|
// These methods use copy() to convert a byte slice to a fixed size array.
|
|
// This approach is used for go1.19 and below.
|
|
|
|
// ToBytes4 is a convenience method for converting a byte slice to a fix
|
|
// sized 4 byte array. This method will truncate the input if it is larger
|
|
// than 4 bytes.
|
|
func ToBytes4(x []byte) [4]byte {
|
|
var y [4]byte
|
|
copy(y[:], x)
|
|
return y
|
|
}
|
|
|
|
// ToBytes20 is a convenience method for converting a byte slice to a fix
|
|
// sized 20 byte array. This method will truncate the input if it is larger
|
|
// than 20 bytes.
|
|
func ToBytes20(x []byte) [20]byte {
|
|
var y [20]byte
|
|
copy(y[:], x)
|
|
return y
|
|
}
|
|
|
|
// ToBytes32 is a convenience method for converting a byte slice to a fix
|
|
// sized 32 byte array. This method will truncate the input if it is larger
|
|
// than 32 bytes.
|
|
func ToBytes32(x []byte) [32]byte {
|
|
var y [32]byte
|
|
copy(y[:], x)
|
|
return y
|
|
}
|
|
|
|
// ToBytes48 is a convenience method for converting a byte slice to a fix
|
|
// sized 48 byte array. This method will truncate the input if it is larger
|
|
// than 48 bytes.
|
|
func ToBytes48(x []byte) [48]byte {
|
|
var y [48]byte
|
|
copy(y[:], x)
|
|
return y
|
|
}
|
|
|
|
// ToBytes64 is a convenience method for converting a byte slice to a fix
|
|
// sized 64 byte array. This method will truncate the input if it is larger
|
|
// than 64 bytes.
|
|
func ToBytes64(x []byte) [64]byte {
|
|
var y [64]byte
|
|
copy(y[:], x)
|
|
return y
|
|
}
|
|
|
|
// ToBytes96 is a convenience method for converting a byte slice to a fix
|
|
// sized 96 byte array. This method will truncate the input if it is larger
|
|
// than 96 bytes.
|
|
func ToBytes96(x []byte) [96]byte {
|
|
var y [96]byte
|
|
copy(y[:], x)
|
|
return y
|
|
}
|