bytesutil

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2019 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package bytesutil defines helper methods for converting integers to byte slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes1

func Bytes1(x uint64) []byte

Bytes1 returns integer x to bytes in little-endian format, x.to_bytes(1, 'big').

func Bytes2

func Bytes2(x uint64) []byte

Bytes2 returns integer x to bytes in little-endian format, x.to_bytes(2, 'big').

func Bytes3

func Bytes3(x uint64) []byte

Bytes3 returns integer x to bytes in little-endian format, x.to_bytes(3, 'big').

func Bytes32

func Bytes32(x uint64) []byte

Bytes32 returns integer x to bytes in little-endian format, x.to_bytes(8, 'little').

func Bytes4

func Bytes4(x uint64) []byte

Bytes4 returns integer x to bytes in little-endian format, x.to_bytes(4, 'little').

func Bytes8

func Bytes8(x uint64) []byte

Bytes8 returns integer x to bytes in little-endian format, x.to_bytes(8, 'little').

func FromBytes4

func FromBytes4(x []byte) uint64

FromBytes4 returns an integer which is stored in the little-endian format(4, 'little') from a byte array.

func FromBytes8

func FromBytes8(x []byte) uint64

FromBytes8 returns an integer which is stored in the little-endian format(8, 'little') from a byte array.

func LowerThan

func LowerThan(x []byte, y []byte) bool

LowerThan returns true if byte slice x is lower than byte slice y. (little-endian format) This is used in spec to compare winning block root hash. Mentioned in spec as "ties broken by favoring lower `shard_block_root` values".

func ToBytes

func ToBytes(x uint64, length int) []byte

ToBytes returns integer x to bytes in little-endian format at the specified length. Spec pseudocode definition:

def int_to_bytes(integer: int, length: int) -> bytes:
  return integer.to_bytes(length, 'little')

func ToBytes32

func ToBytes32(x []byte) [32]byte

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 ToBytes48

func ToBytes48(x []byte) [48]byte

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 ToBytes8

func ToBytes8(x []byte) [8]byte

ToBytes8 is a convenience method for converting a byte slice to a fix sized 8 byte array. This method will truncate the input if it is larger than 8 bytes.

func ToBytes96

func ToBytes96(x []byte) [96]byte

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 ToLowInt64

func ToLowInt64(x []byte) int64

ToLowInt64 returns the lowest 8 bytes interpreted as little endian.

func Trunc

func Trunc(x []byte) []byte

Trunc truncates the byte slices to 6 bytes.

func Xor

func Xor(x []byte, y []byte) []byte

Xor xors the bytes in x and y and returns the result.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL