Documentation ¶
Overview ¶
Package trinary provides functions for validating and converting Trits and Trytes.
Index ¶
- Variables
- func CanBeHash(trits Trits) bool
- func CanTritsToTrytes(trits Trits) bool
- func TrailingZeros(trits Trits) int64
- func TritsEqual(a Trits, b Trits) (bool, error)
- func TritsToBytes(trits Trits) (bytes []byte)
- func TritsToInt(t Trits) int64
- func TrytesToBytes(trytes Trytes) ([]byte, error)
- func ValidTrit(t int8) bool
- func ValidTrits(t Trits) error
- func ValidTryte(t rune) error
- func ValidTrytes(trytes Trytes) error
- type Hash
- type Hashes
- type Trits
- func AddTrits(a Trits, b Trits) Trits
- func BytesToTrits(bytes []byte, numTrits ...int) (trits Trits, err error)
- func IntToTrits(value int64) Trits
- func MustTrytesToTrits(trytes Trytes) Trits
- func NewTrits(t []int8) (Trits, error)
- func PadTrits(trits Trits, size int) Trits
- func ReverseTrits(trits Trits) Trits
- func TrytesToTrits(trytes Trytes) (Trits, error)
- type Trytes
Constants ¶
This section is empty.
Variables ¶
var ( // TryteToTritsLUT is a Look-up-table for Trytes to Trits conversion. TryteToTritsLUT = [][]int8{ {0, 0, 0}, {1, 0, 0}, {-1, 1, 0}, {0, 1, 0}, {1, 1, 0}, {-1, -1, 1}, {0, -1, 1}, {1, -1, 1}, {-1, 0, 1}, {0, 0, 1}, {1, 0, 1}, {-1, 1, 1}, {0, 1, 1}, {1, 1, 1}, {-1, -1, -1}, {0, -1, -1}, {1, -1, -1}, {-1, 0, -1}, {0, 0, -1}, {1, 0, -1}, {-1, 1, -1}, {0, 1, -1}, {1, 1, -1}, {-1, -1, 0}, {0, -1, 0}, {1, -1, 0}, {-1, 0, 0}, } )
Functions ¶
func CanTritsToTrytes ¶
CanTritsToTrytes returns true if t can be converted to trytes.
func TrailingZeros ¶
TrailingZeros returns the number of trailing zeros of the given trits.
func TritsEqual ¶
TritsEqual returns true if t and b are equal Trits
func TritsToBytes ¶
TritsToBytes packs an array of trits into an array of bytes (5 packed trits in 1 byte)
func TritsToInt ¶
TritsToInt converts a slice of trits into an integer and assumes little-endian notation.
func TrytesToBytes ¶
TrytesToBytes is only defined for hashes (81 Trytes). It returns 48 bytes.
func ValidTryte ¶
ValidTryte returns the validity of a tryte (must be rune A-Z or 9)
func ValidTrytes ¶
ValidTrytes returns true if t is made of valid trytes.
Types ¶
type Trits ¶
type Trits = []int8
Trits is a slice of int8. You should not use cast, use NewTrits instead to ensure the validity.
func BytesToTrits ¶
BytesToTrits unpacks an array of bytes into an array of trits
func MustTrytesToTrits ¶
MustTrytesToTrits converts a slice of trytes into trits.
func TrytesToTrits ¶
TrytesToTrits converts a slice of trytes into trits.
type Trytes ¶
type Trytes = string
Trytes is a string of trytes. Use NewTrytes() instead of typecasting.
func BytesToTrytes ¶
BytesToTrytes converts bytes to Trytes. Returns an error if the bytes slice is not 48 in length.
func MustTritsToTrytes ¶
MustTritsToTrytes converts a slice of trits into trytes. Panics if len(t)%3!=0
func TritsToTrytes ¶
TritsToTrytes converts a slice of trits into trytes. Returns an error if len(t)%3!=0