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 DecodeInt64(t Trits) (value int64, size uint64, err error)
- func EncodedLength(value int64) uint64
- func MinTrits(value int64) uint64
- func MustAbsInt64(n int64) int64
- func MustTrytesToBytes(trytes Trytes) []byte
- func Sum(a int8, b int8) int8
- 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 TrytesToInt(t Trytes) int64
- 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 EncodeInt64(value int64) (t Trits, size uint64, 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
- func BytesToTrytes(bytes []byte, numTrytes ...int) (Trytes, error)
- func IntToTrytes(value int64, trytesCnt int) Trytes
- func MustBytesToTrytes(bytes []byte, numTrytes ...int) Trytes
- func MustTritsToTrytes(trits Trits) Trytes
- func NewTrytes(s string) (Trytes, error)
- func Pad(trytes Trytes, size int) Trytes
- func TritsToTrytes(trits Trits) (Trytes, error)
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}, } // Pow27LUT is a Look-up-table for Decoding Trits to int64 Pow27LUT = []int64{1, 27, 729, 19683, 531441, 14348907, 387420489, 10460353203, 282429536481, 7625597484987, 205891132094649, 5559060566555523, 150094635296999136, 4052555153018976256} )
Functions ¶
func CanTritsToTrytes ¶
CanTritsToTrytes returns true if t can be converted to trytes.
func DecodeInt64 ¶
DecodeInt64 decodes a slice of trits with encoding information as an int64.
func EncodedLength ¶
EncodedLength returns the length of trits needed to encode the value + encoding information.
func MustAbsInt64 ¶
MustAbsInt64 returns the absolute value of an int64.
func MustTrytesToBytes ¶
MustTrytesToBytes is only defined for hashes (81 Trytes). It returns 48 bytes.
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 TrytesToInt ¶
TrytesToInt converts a slice of trytes to int64.
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 EncodeInt64 ¶
EncodeInt64 encodes an int64 as a slice of trits with encoding information.
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 IntToTrytes ¶
IntToTrytes converts int64 to a slice of trytes.
func MustBytesToTrytes ¶
MustBytesToTrytes converts bytes to Trytes.
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