Documentation ¶
Overview ¶
Package bytesutil defines helper methods for converting integers to byte slices.
Index ¶
- func Bytes1(x uint64) []byte
- func Bytes2(x uint64) []byte
- func Bytes3(x uint64) []byte
- func Bytes32(x uint64) []byte
- func Bytes4(x uint64) []byte
- func Bytes8(x uint64) []byte
- func BytesToEpochBigEndian(b []byte) types.Epoch
- func BytesToSlotBigEndian(b []byte) types.Slot
- func BytesToUint64BigEndian(b []byte) uint64
- func ClearBit(b []byte, i int) []byte
- func Copy2dBytes(ary [][]byte) [][]byte
- func EpochToBytesBigEndian(i types.Epoch) []byte
- func EpochToBytesLittleEndian(i types.Epoch) []byte
- func FromBool(x bool) byte
- func FromBytes2(x []byte) uint16
- func FromBytes4(x []byte) uint64
- func FromBytes48(x [48]byte) []byte
- func FromBytes48Array(x [][48]byte) [][]byte
- func FromBytes8(x []byte) uint64
- func HighestBitIndex(b []byte) (int, error)
- func HighestBitIndexAt(b []byte, index int) (int, error)
- func IsHex(b []byte) (bool, error)
- func MakeEmptyBitlists(i int) []byte
- func PadTo(b []byte, size int) []byte
- func ReverseBytes32Slice(arr [][32]byte) [][32]byte
- func SafeCopyBytes(cp []byte) []byte
- func SetBit(b []byte, i int) []byte
- func SlotToBytesBigEndian(i types.Slot) []byte
- func ToBool(x byte) bool
- func ToBytes(x uint64, length int) []byte
- func ToBytes32(x []byte) [32]byte
- func ToBytes4(x []byte) [4]byte
- func ToBytes48(x []byte) [48]byte
- func ToBytes64(x []byte) [64]byte
- func ToLowInt64(x []byte) int64
- func Trunc(x []byte) []byte
- func Uint64ToBytesBigEndian(i uint64) []byte
- func Uint64ToBytesLittleEndian(i uint64) []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bytes32 ¶
Bytes32 returns integer x to bytes in little-endian format, x.to_bytes(32, 'little').
func BytesToEpochBigEndian ¶ added in v1.2.2
BytesToEpochBigEndian conversion.
func BytesToSlotBigEndian ¶ added in v1.2.2
BytesToSlotBigEndian conversion.
func BytesToUint64BigEndian ¶ added in v1.0.0
BytesToUint64BigEndian conversion. Returns 0 if empty bytes or byte slice with length less than 8.
func ClearBit ¶ added in v0.3.8
ClearBit clears the index `i` of bitlist `b`. Returns the original bitlist if the index `i` is out of range.
func Copy2dBytes ¶ added in v0.3.2
Copy2dBytes will copy and return a non-nil 2d byte array, otherwise it returns nil.
func EpochToBytesBigEndian ¶ added in v1.2.2
EpochToBytesBigEndian conversion.
func EpochToBytesLittleEndian ¶ added in v1.2.2
EpochToBytesLittleEndian conversion.
func FromBool ¶ added in v0.3.2
FromBool is a convenience method for converting a bool to a byte. This method will use the first bit to generate the returned value.
func FromBytes2 ¶ added in v0.3.2
FromBytes2 returns an integer which is stored in the little-endian format(2, 'little') from a byte array.
func FromBytes4 ¶
FromBytes4 returns an integer which is stored in the little-endian format(4, 'little') from a byte array.
func FromBytes48 ¶ added in v0.3.0
FromBytes48 is a convenience method for converting a fixed-size byte array to a byte slice.
func FromBytes48Array ¶ added in v0.3.0
FromBytes48Array is a convenience method for converting an array of fixed-size byte arrays to an array of byte slices.
func FromBytes8 ¶
FromBytes8 returns an integer which is stored in the little-endian format(8, 'little') from a byte array.
func HighestBitIndex ¶ added in v0.3.8
HighestBitIndex returns the index of the highest bit set from bitlist `b`.
func HighestBitIndexAt ¶ added in v0.3.8
HighestBitIndexAt returns the index of the highest bit set from bitlist `b` that is at `index` (inclusive).
func IsHex ¶ added in v1.4.1
IsHex checks whether the byte array is a hex number prefixed with '0x'.
func MakeEmptyBitlists ¶ added in v0.3.8
MakeEmptyBitlists returns an empty bitlist with input size `i`.
func PadTo ¶ added in v0.3.6
PadTo pads a byte slice to the given size. If the byte slice is larger than the given size, the original slice is returned.
func ReverseBytes32Slice ¶ added in v0.3.2
ReverseBytes32Slice will reverse the provided slice's order.
func SafeCopyBytes ¶ added in v0.3.2
SafeCopyBytes will copy and return a non-nil byte array, otherwise it returns nil.
func SetBit ¶ added in v0.3.8
SetBit sets the index `i` of bitlist `b` to 1. It grows and returns a longer bitlist with 1 set if index `i` is out of range.
func SlotToBytesBigEndian ¶ added in v1.2.2
SlotToBytesBigEndian conversion.
func ToBool ¶ added in v0.3.2
ToBool is a convenience method for converting a byte to a bool. This method will use the first bit of the 0 byte to generate the returned value.
func ToBytes ¶
ToBytes returns integer x to bytes in little-endian format at the specified length. Spec defines similar method uint_to_bytes(n: uint) -> bytes, which is equivalent to ToBytes(n, 8).
func ToBytes32 ¶
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 ToBytes4 ¶ added in v0.3.2
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 ToBytes48 ¶
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 ToBytes64 ¶ added in v1.0.0
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 ToLowInt64 ¶
ToLowInt64 returns the lowest 8 bytes interpreted as little endian.
func Uint64ToBytesBigEndian ¶ added in v1.0.0
Uint64ToBytesBigEndian conversion.
func Uint64ToBytesLittleEndian ¶ added in v1.0.0
Uint64ToBytesLittleEndian conversion.
Types ¶
This section is empty.