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 MinTrits(value int64) int
- func MustPutTryteTrits(trits []int8, v int8)
- func MustTritsToTryteValue(trits Trits) int8
- func MustTryteToTryteValue(t byte) int8
- func MustTryteValueToTryte(v int8) byte
- func Sum(a int8, b int8) int8
- func TrailingZeros(trits Trits) int
- func TritsEqual(a Trits, b Trits) (bool, error)
- func TritsToInt(t Trits) int64
- func TrytesToInt(t Trytes) int64
- func ValidTrit(t int8) bool
- func ValidTrits(trits 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 IntToTrits(value int64) Trits
- func MustPadTrits(trits Trits, n int) Trits
- func MustTrytesToTrits(trytes Trytes) Trits
- func NewTrits(t []int8) (Trits, error)
- func PadTrits(trits Trits, n int) (Trits, error)
- func ReverseTrits(trits Trits) Trits
- func TrytesToTrits(trytes Trytes) (Trits, error)
- type Trytes
Constants ¶
This section is empty.
Variables ¶
var ( // TryteValueToTritsLUT is a lookup table to convert tryte values into trits. TryteValueToTritsLUT = [TryteRadix][TritsPerTryte]int8{ {-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}, {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}, } // TryteValueToTyteLUT is a lookup table to convert tryte values into trytes. TryteValueToTyteLUT = [TryteRadix]byte{'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'} // TryteToTryteValueLUT is a lookup table to convert trytes into tryte values. TryteToTryteValueLUT = [...]int8{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, } // 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 MustPutTryteTrits ¶
MustPutTryteTrits converts v in [-13,13] to its corresponding 3-trit value and writes this to trits. It panics on invalid input.
func MustTritsToTryteValue ¶
MustTritsToTryteValue converts a slice of 3 into its corresponding value. It performs no validation on the provided inputs (therefore might return an invalid representation) and might panic.
func MustTryteToTryteValue ¶
MustTryteToTryteValue converts a tryte char t in [9A-Z] to a tryte value in [-13,13]. Performs no validation on t (therefore might return an invalid representation) and might panic.
func MustTryteValueToTryte ¶
MustTryteValueToTryte converts the value of a tryte v in [-13,13] to a tryte char in [9A-Z]. It panics when v is an invalid value.
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 TritsToInt ¶
TritsToInt converts a slice of trits into an integer and assumes little-endian notation.
func TrytesToInt ¶
TrytesToInt converts a slice of trytes to int64.
func ValidTrits ¶
ValidTrits returns true if t is valid trits (non-empty and -1, 0 or 1).
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 MustPadTrits ¶
MustPadTrits pads the given trits with 0 up to the given size. Performs no validation on the provided inputs (therefore might return an invalid representation) and might panic.
func MustTrytesToTrits ¶
MustTrytesToTrits converts a slice of trytes into trits. Performs no validation on the provided inputs (therefore might return an invalid representation) and might panic.
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 IntToTrytes ¶
IntToTrytes converts int64 to a slice of trytes.
func MustPad ¶
MustPad pads the given trytes with 9s up to the given size. Performs no validation on the provided inputs (therefore might return an invalid representation) and might panic.
func MustTritsToTrytes ¶
MustTritsToTrytes converts a slice of trits into trytes. Performs no validation on the input trits and might therefore return an invalid trytes representation (without a panic).
func TritsToTrytes ¶
TritsToTrytes converts a slice of trits into trytes. Returns an error if len(t)%3!=0