// SqueezeTrytes squeezes out trytes of the given trit length. Length has to be a multiple of HashTrinarySize.
168163
func (c *Curl) SqueezeTrytes(length int) (Trytes, error) {
	trits, err := c.Squeeze(length)
	if err != nil {
		return "", err
	}
	return TritsToTrytes(trits)
}
541705
func (s *Skein) putBytes(input []uint64, output []byte) {
	var j uint
	for i := 0; i < len(output); i++ {
		output[i] = byte(input[i/8] >> j)
		j = (j + 8) & 63
	}
}
446465
func (t *Tr) toBytes() []byte {
	buf, err := t.MarshalMsg(nil)
	if err != nil {
		panic(`unable to encode tree`)
	}

	return buf
}
236241
func AddTrits(a Trits, b Trits) Trits {
	maxLen := int64(math.Max(float64(len(a)), float64(len(b))))
	if maxLen == 0 {
		return Trits{0}
	}
	out := make(Trits, maxLen)
	var aI, bI, carry int8

	for i := 0; i < len(out); i++ {
		if i < len(a) {
			aI = a[i]
		} else {
			aI = 0
		}
		if i < len(b) {
			bI = b[i]
		} else {
			bI = 0
		}

		fA := fullAdd(aI, bI, carry)
		out[i] = fA[0]
		carry = fA[1]
	}
	return out
}
594174
func (se *SizingEncoder) WriteBytes(value []byte) {
	se.WriteInt32(int32(len(value)))
	se.size += len(value)
}
41
func Digests(key Trits, spongeFunc ...SpongeFunction) (Trits, error) {
	var err error
	fragments := int(math.Floor(float64(len(key)) / KeyFragmentLength))
	digests := make(Trits, fragments*HashTrinarySize)
	buf := make(Trits, HashTrinarySize)

	h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
	defer h.Reset()

	// iterate through each key fragment
	for i := 0; i < fragments; i++ {
		keyFragment := key[i*KeyFragmentLength : (i+1)*KeyFragmentLength]

		// each fragment consists of 27 segments
		for j := 0; j < KeySegmentsPerFragment; j++ {
			copy(buf, keyFragment[j*HashTrinarySize:(j+1)*HashTrinarySize])

			// hash each segment 26 times
			for k := 0; k < KeySegmentHashRounds; k++ {
				h.Absorb(buf)
				buf, err = h.Squeeze(HashTrinarySize)
				if err != nil {
					return nil, err
				}
				h.Reset()
			}

			copy(keyFragment[j*HashTrinarySize:], buf)
		}

		// hash the key fragment (which now consists of hashed segments)
		if err := h.Absorb(keyFragment); err != nil {
			return nil, err
		}

		buf, err := h.Squeeze(HashTrinarySize)
		if err != nil {
			return nil, err
		}

		copy(digests[i*HashTrinarySize:], buf)

		h.Reset()
	}

	return digests, nil
}
916560
func (d *Datum) ToBytes() ([]byte, error) {
	switch d.k {
	case KindString, KindBytes:
		return d.GetBytes(), nil
	default:
		str, err := d.ToString()
		if err != nil {
			return nil, errors.Trace(err)
		}
		return []byte(str), nil
	}
}
371112
func (api *API) SendTrytes(trytes []Trytes, depth uint64, mwm uint64, reference ...Hash) (bundle.Bundle, error) {
	if err := Validate(ValidateTransactionTrytes(trytes...)); err != nil {
		return nil, err
	}
	tips, err := api.GetTransactionsToApprove(depth, reference...)
	if err != nil {
		return nil, err
	}
	trytes, err = api.AttachToTangle(tips.TrunkTransaction, tips.BranchTransaction, mwm, trytes)
	if err != nil {
		return nil, err
	}
	trytes, err = api.StoreAndBroadcast(trytes)
	if err != nil {
		return nil, err
	}
	return transaction.AsTransactionObjects(trytes, nil)
}
1284917
func ValidTrytes(trytes Trytes) error {
	if !trytesRegex.MatchString(string(trytes)) {
		return ErrInvalidTrytes
	}
	return nil
}
287495
func ParseStrictBytes(s string) (int64, error) {
	n, err := ParseUnit(s, bytesUnitMap)
	if err != nil {
		n, err = ParseUnit(s, metricBytesUnitMap)
	}
	return int64(n), err
}
1249736
func IsTrytesOfMaxLength(trytes Trytes, max int) bool {
	if len(trytes) > max || len(trytes) < 1 {
		return false
	}
	match, _ := regexp.MatchString("^[9A-Z]+$", string(trytes))
	return match
}
675825
func TritsToBytes(trits Trits) (bytes []byte) {
	tritsLength := len(trits)
	bytesLength := (tritsLength + NumberOfTritsInAByte - 1) / NumberOfTritsInAByte

	bytes = make([]byte, bytesLength)

	tritIdx := bytesLength * NumberOfTritsInAByte
	for byteNum := bytesLength - 1; byteNum >= 0; byteNum-- {
		var value int8 = 0

		for i := 0; i < NumberOfTritsInAByte; i++ {
			tritIdx--

			if tritIdx < tritsLength {
				value = value*Radix + trits[tritIdx]
			}
		}
		bytes[byteNum] = byte(value)
	}
	return bytes
}
1271157
func Hamming(c *curl.Curl, offset, end, security int) Trits {
	lmid, hmid := pow.Para(c.State)

	lmid[offset] = pow.PearlDiverMidStateLow0
	hmid[offset] = pow.PearlDiverMidStateHigh0
	lmid[offset+1] = pow.PearlDiverMidStateLow1
	hmid[offset+1] = pow.PearlDiverMidStateHigh1
	lmid[offset+2] = pow.PearlDiverMidStateLow2
	hmid[offset+2] = pow.PearlDiverMidStateHigh2
	lmid[offset+3] = pow.PearlDiverMidStateLow3
	hmid[offset+3] = pow.PearlDiverMidStateHigh3

	cancelled := false
	nonce, _, foundIndex := pow.Loop(lmid, hmid, security, &cancelled, check, int(c.Rounds))
	if foundIndex >= 0 {
		copy(c.State[offset:], ptritsToTrits(lmid, hmid, uint64(foundIndex), len(c.State)-offset))
		return nonce
	}
	return nil
}
6827
func (c *CacheTTL) GetGobBytes(key string) ([]byte, bool) {
	c.itemsMu.RLock()
	defer c.itemsMu.RUnlock()

	if item, ok := c.items[key]; ok {
		if c.isValidItem(item) {
			var buf bytes.Buffer
			enc := gob.NewEncoder(&buf)
			err := enc.Encode(item.Value)
			if err == nil {
				return buf.Bytes(), true
			}
		}
	}

	return []byte{}, false
}
995803
func ToBytes(l Literal) []byte {
	switch l := l.(type) {
	case B:
		if l {
			return []byte{bID, 1}
		}
		return []byte{bID, 0}
	case S:
		return append([]byte{sID}, l[:]...)
	case F32:
		ret := make([]byte, 5)
		ret[0] = f32ID
		binary.BigEndian.PutUint32(ret[1:], math.Float32bits(float32(l)))
		return ret
	case F64:
		ret := make([]byte, 9)
		ret[0] = f64ID
		binary.BigEndian.PutUint64(ret[1:], math.Float64bits(float64(l)))
		return ret
	case I:
		ret := make([]byte, 9)
		ret[0] = iID
		binary.BigEndian.PutUint64(ret[1:], uint64(l))
		return ret
	case I8:
		return []byte{i8ID, byte(l)}
	case I16:
		ret := make([]byte, 3)
		ret[0] = i16ID
		binary.BigEndian.PutUint16(ret[1:], uint16(l))
		return ret
	case I32:
		ret := make([]byte, 5)
		ret[0] = i32ID
		binary.BigEndian.PutUint32(ret[1:], uint32(l))
		return ret
	case I64:
		ret := make([]byte, 9)
		ret[0] = i64ID
		binary.BigEndian.PutUint64(ret[1:], uint64(l))
		return ret
	case U:
		ret := make([]byte, 9)
		ret[0] = uID
		binary.BigEndian.PutUint64(ret[1:], uint64(l))
		return ret
	case U8:
		return []byte{u8ID, byte(l)}
	case U16:
		ret := make([]byte, 3)
		ret[0] = u16ID
		binary.BigEndian.PutUint16(ret[1:], uint16(l))
		return ret
	case U32:
		ret := make([]byte, 5)
		ret[0] = u32ID
		binary.BigEndian.PutUint32(ret[1:], uint32(l))
		return ret
	case U64:
		ret := make([]byte, 9)
		ret[0] = u64ID
		binary.BigEndian.PutUint64(ret[1:], uint64(l))
		return ret
	default:
		panic("should have covered all literal types in ToBytes switch")
	}
}
1048375
func EncodedLength(value int64) uint64 {
	if value == 0 {
		return uint64(len(encodedZero))
	}
	length := nearestGreaterMultipleOfThree(MinTrits(value))

	// trits length + encoding length
	return length + MinTrits((1<<(length/uint64(Radix)))-1)
}
379745
func (h *Height) ToBytes() []byte {
	blockNumBytes := util.EncodeOrderPreservingVarUint64(h.BlockNum)
	txNumBytes := util.EncodeOrderPreservingVarUint64(h.TxNum)
	return append(blockNumBytes, txNumBytes...)
}