// ToByteArray converts the sequence into a byte array
17206
func (s *sequence) toByteArray() ([]byte, error) {
	var bb []byte

	p := s
	for p != nil {
		b := make([]byte, 12)
		binary.BigEndian.PutUint32(b[0:], p.block)
		binary.BigEndian.PutUint64(b[4:], p.count)
		bb = append(bb, b...)
		p = p.next
	}

	return bb, nil
}
1214135
func ByteToString(a []byte) string {
	const hexDigit = "0123456789abcdef"
	if len(a) == 0 {
		return ""
	}
	buf := make([]byte, 0, len(a)*3-1)
	for i, b := range a {
		if i > 0 {
			buf = append(buf, ':')
		}
		buf = append(buf, hexDigit[b>>4])
		buf = append(buf, hexDigit[b&0xF])
	}
	return string(buf)
}
405974
func (p *adxl345PowerCtl) toByte() (bits uint8) {
	bits = 0x00
	bits = bits | (p.link << 5)
	bits = bits | (p.autoSleep << 4)
	bits = bits | (p.measure << 3)
	bits = bits | (p.sleep << 2)
	bits = bits | p.wakeUp

	return bits
}
186061
func (h Hash) MarshalBinary() (data []byte, err error) {
	if h == (Hash{}) {
		return nil, nil
	}

	if !h.IsValid() {
		return nil, errors.WithStack(InvalidHashError{h})
	}

	return []byte(h.h), nil
}
193566
func (ra *roaringArray) toBytes() ([]byte, error) {
	var buf bytes.Buffer
	_, err := ra.writeTo(&buf)
	return buf.Bytes(), err
}
891574
func ToBytes(s string) (uint64, error) {
	s = strings.TrimSpace(s)
	s = strings.ToUpper(s)

	i := strings.IndexFunc(s, unicode.IsLetter)

	if i == -1 {
		return 0, invalidByteQuantityError
	}

	bytesString, multiple := s[:i], s[i:]
	bytes, err := strconv.ParseFloat(bytesString, 64)
	if err != nil || bytes <= 0 {
		return 0, invalidByteQuantityError
	}

	switch multiple {
	case "T", "TB", "TIB":
		return uint64(bytes * TERABYTE), nil
	case "G", "GB", "GIB":
		return uint64(bytes * GIGABYTE), nil
	case "M", "MB", "MIB":
		return uint64(bytes * MEGABYTE), nil
	case "K", "KB", "KIB":
		return uint64(bytes * KILOBYTE), nil
	case "B":
		return uint64(bytes), nil
	default:
		return 0, invalidByteQuantityError
	}
}
328354
func (s *sequence) fromByteArray(data []byte) error {
	l := len(data)
	if l%12 != 0 {
		return fmt.Errorf("cannot deserialize byte sequence of length %d (%v)", l, data)
	}

	p := s
	i := 0
	for {
		p.block = binary.BigEndian.Uint32(data[i : i+4])
		p.count = binary.BigEndian.Uint64(data[i+4 : i+12])
		i += 12
		if i == l {
			break
		}
		p.next = &sequence{}
		p = p.next
	}

	return nil
}
960695
func (p Property) IsArray() bool {
	return p.Type == arrayType || strings.HasSuffix(p.TypeString(), "[]")
}
577503
func (self *Commands) IsArray(value interface{}) error {
	if typeutil.IsArray(value) {
		return nil
	} else {
		return fmt.Errorf("Expected array value")
	}
}
1253477
func ToBytes(v Val) []byte {
	if v == nil {
		return nil
	}
	b, ok := v.([]byte)
	if !ok {
		ba, ok := v.(BytesAddress)
		if !ok {
			panic(fmt.Sprintf("unsupported value type %T", v))
		}
		b = ba.Address()
	}
	return b
}
230444
func (s *framedDecoderStream) isValidByteSequence(p []byte) bool {
	for _, b := range p {
		if !s.params.Encoding.IsValidByte(b) {
			return false
		}
	}
	return true
}
1005839
func HashBytes(h crypto.Hash, content []byte) HexDigest {
	a := h.New()
	_, _ = a.Write(content)
	return Sum(a)
}
1033661
func ToHexArray(b [][]byte) []string {
	r := make([]string, len(b))
	for i := range b {
		r[i] = ToHex(b[i])
	}
	return r
}
885277
func int8ArrayToByteArray(in []int8) []byte {
	bts := make([]byte, len(in))
	for i, c := range in {
		bts[i] = byte(c)
	}
	return bytes.Trim(bts, "\x00")
}
67351
func (pub *PublicKey) ToBytesUncompressed() (b []byte) {
	/* See Certicom SEC1 2.3.3, pg. 10 */

	x := pub.X.Bytes()
	y := pub.Y.Bytes()

	/* Pad X and Y coordinate bytes to 32-bytes */
	padded_x := append(bytes.Repeat([]byte{0x00}, 32-len(x)), x...)
	padded_y := append(bytes.Repeat([]byte{0x00}, 32-len(y)), y...)

	/* Add prefix 0x04 for uncompressed coordinates */
	return append([]byte{0x04}, append(padded_x, padded_y...)...)
}
886843
func (s *stack) PeekByteArray(idx int32) ([]byte, error) {
	sz := int32(len(s.stk))
	if idx < 0 || idx >= sz {
		str := fmt.Sprintf("index %d is invalid for stack size %d", idx,
			sz)
		return nil, scriptError(ErrInvalidStackOperation, str)
	}

	return s.stk[sz-idx-1], nil
}
647501
func UintArray(name string, values []uint) FieldOpt {
	inType := inTypeNull
	var writeItem func(*eventData, uint)
	switch unsafe.Sizeof(values[0]) {
	case 4:
		inType = inTypeUint32
		writeItem = func(ed *eventData, item uint) { ed.writeUint32(uint32(item)) }
	case 8:
		inType = inTypeUint64
		writeItem = func(ed *eventData, item uint) { ed.writeUint64(uint64(item)) }
	default:
		panic("Unsupported uint size")
	}

	return func(em *eventMetadata, ed *eventData) {
		em.writeArray(name, inType, outTypeDefault, 0)
		ed.writeUint16(uint16(len(values)))
		for _, v := range values {
			writeItem(ed, v)
		}
	}
}