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) int
- func MustPutTryteTrits(trits []int8, v int8)
- func MustTritsToBytes(trits Trits) (bytes []byte)
- func MustTryteToTryteValue(t byte) int8
- func MustTryteValueToTryte(v int8) byte
- func MustTrytesToBytes(trytes Trytes) []byte
- func Sum(a int8, b int8) int8
- func TrailingZeros(trits Trits) int
- func TritsEqual(a Trits, b Trits) (bool, error)
- func TritsToBytes(trits Trits) ([]byte, error)
- func TritsToInt(t Trits) int64
- func TrytesToBytes(trytes Trytes) ([]byte, error)
- func TrytesToInt(t Trytes) int64
- func ValidBytesForTrits(bytes []byte) error
- 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 BytesToTrits(bytes []byte, numTrits ...int) (Trits, error)
- func EncodeInt64(value int64) (t Trits, size uint64, err error)
- func IntToTrits(value int64) Trits
- func MustBytesToTrits(bytes []byte, numTrits ...int) 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
- func BytesToTrytes(bytes []byte, numTrytes ...int) (Trytes, error)
- func IntToTrytes(value int64, trytesCnt int) Trytes
- func MustBytesToTrytes(bytes []byte, numTrytes ...int) Trytes
- func MustPad(trytes Trytes, n int) Trytes
- func MustTritsToTrytes(trits Trits) Trytes
- func NewTrytes(s string) (Trytes, error)
- func Pad(trytes Trytes, n int) (Trytes, error)
- func TritsToTrytes(trits Trits) (Trytes, error)
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 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 MustPutTryteTrits ¶
MustPutTryteTrits converts v in [-13,13] to its corresponding 3-trit value and writes this to trits. It panics on invalid input.
func MustTritsToBytes ¶
MustTritsToBytes packs an array of trits into an array of bytes (5 packed trits in 1 byte). 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]. It panics when t is an invalid tryte.
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 MustTrytesToBytes ¶
MustTrytesToBytes packs trytes into a slice of bytes (5 packed trits in 1 byte). Performs no validation on the provided inputs (therefore might return an invalid representation) and might panic.
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 packs trytes into a slice of bytes (5 packed trits in 1 byte).
func TrytesToInt ¶
TrytesToInt converts a slice of trytes to int64.
func ValidBytesForTrits ¶
ValidBytesForTrits checks whether the given bytes are valid for bytes to trits conversion (5 packed trits in 1 byte).
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 BytesToTrits ¶
BytesToTrits unpacks an array of bytes (5 packed trits in 1 byte) into an array of trits.
func EncodeInt64 ¶
EncodeInt64 encodes an int64 as a slice of trits with encoding information.
func MustBytesToTrits ¶
MustBytesToTrits unpacks an array of bytes (5 packed trits in 1 byte) into an array of trits. Performs no validation on the provided inputs (therefore might return an invalid representation) and might panic.
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 BytesToTrytes ¶
BytesToTrytes unpacks a slice of bytes (5 packed trits in 1 byte) into trytes.
func IntToTrytes ¶
IntToTrytes converts int64 to a slice of trytes.
func MustBytesToTrytes ¶
MustBytesToTrytes unpacks a slice of bytes (5 packed trits in 1 byte) into trytes. Performs no validation on the provided inputs (therefore might return an invalid representation) and might panic.
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