bitfields

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2020 License: MIT Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitIndex

func BitIndex(v byte) (out uint64)

Get index of left-most 1 bit. 0 (incl.) to 8 (excl.)

func BitlistCheck

func BitlistCheck(b []byte, limit uint64) error

Helper function to implement Bitlist with. It checks if:

  1. the raw bitlist is not empty, there must be a 1 bit to determine the length.
  2. the bitlist has a leading 1 bit in the last byte to determine the length with.
  3. if b has no more than given limit in bits.

func BitlistCheckByteLen added in v0.1.4

func BitlistCheckByteLen(byteLen uint64, bitLimit uint64) error

func BitlistCheckLastByte added in v0.1.4

func BitlistCheckLastByte(last byte, limit uint64) error

func BitlistLen

func BitlistLen(b []byte) uint64

Returns the length of the bitlist. And although strictly speaking invalid. a sane default is returned for:

  • an empty raw bitlist: a default 0 bitlist will be of length 0 too.
  • a bitlist with a leading 0 byte: return the bitlist raw bit length, excluding the last byte (As if it was full 0 padding).

func BitvectorCheck

func BitvectorCheck(b []byte, n uint64) error

Helper function to implement Bitvector with. It checks if:

  1. b has the same amount of bytes as necessary for n bits.
  2. unused bits in b are 0

func BitvectorCheckByteLen added in v0.1.4

func BitvectorCheckByteLen(byteLen uint64, bitLength uint64) error

func BitvectorCheckLastByte added in v0.1.4

func BitvectorCheckLastByte(last byte, n uint64) error

func GetBit

func GetBit(b []byte, i uint64) bool

Helper function to implement Bitfields with. Assumes i is a valid bit-index to retrieve a bit from bytes b.

func IsZeroBitlist

func IsZeroBitlist(b []byte) bool

Checks if the bitList is fully zeroed (except the leading bit)

func SetBit

func SetBit(b []byte, i uint64, v bool)

Helper function to implement Bitfields with. Assumes i is a valid bit-index to set a bit within bytes b.

Types

type Bitfield

type Bitfield interface {
	Get(i uint64) bool
	Set(i uint64, v bool)
}

General base interface for Bitlists and Bitvectors Note for Bitfields to work with the SSZ functionality:

  • Bitlists need to be of kind []byte (packed bits, incl delimiter bit)
  • Bitvectors need to be of kind [N]byte (packed bits)

type Bitlist

type Bitlist interface {
	Bitfield
	BitlistMeta
}

type BitlistMeta

type BitlistMeta interface {
	// Length (in bits) of the Bitlist.
	SizedBits
	// BitLimit (in bits) of the Bitlist.
	lists.List
}

type Bitvector

type Bitvector interface {
	Bitfield
	BitvectorMeta
}

type BitvectorMeta

type BitvectorMeta interface {
	SizedBits
}

Bitvectors should have a pointer-receiver BitLen function to derive its fixed bit-length from.

type CheckedBitfield

type CheckedBitfield interface {
	Check() error
}

bitfields implementing this can be checked to be of a valid or not. Useful for untrusted bitfields. See BitlistCheck and BitvectorCheck to easily implement the validity checks.

type SizedBits

type SizedBits interface {
	BitLen() uint64
}

the exact bitlength can be determined for bitfields implementing this method.

Jump to

Keyboard shortcuts

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