// NewBytes uses the image package's decoder to convert the bytes given to
// an xgraphics.Imag value.
// Decoding an image can cause an error.
486575
func NewBytes(X *xgbutil.XUtil, bs []byte) (*Image, error) {
	img, _, err := image.Decode(bytes.NewReader(bs))
	if err != nil {
		return nil, err
	}
	return NewConvert(X, img), nil
}
162806
func (Encoder) AppendBytes(dst, s []byte) []byte {
	dst = append(dst, '"')
	for i := 0; i < len(s); i++ {
		if !noEscapeTable[s[i]] {
			dst = appendBytesComplex(dst, s, i)
			return append(dst, '"')
		}
	}
	dst = append(dst, s...)
	return append(dst, '"')
}
738003
func (be *BinaryEncoder) WriteBytes(x []byte) {
	be.WriteLong(int64(len(x)))
	_, _ = be.buffer.Write(x)
}
691013
func ReadBytes(data []byte, opts ...Option) (Node, error) {
	return Read(bytes.NewBuffer(data), opts...)
}
412423
func (r *Rollsum32Base) AddByte(b byte) {
	r.a += uint32(b)
	r.b += r.a
}
437101
func (p *Parser) ParseBytes(b []byte, v interface{}) error {
	return p.Parse(bytes.NewReader(b), v)
}
256245
func (b *NexthopRegisterBody) DecodeFromBytes(data []byte, version uint8) error {
	offset := 0

	// List of Registered Nexthops
	b.Nexthops = []*RegisteredNexthop{}
	for len(data[offset:]) > 0 {
		nh := new(RegisteredNexthop)
		err := nh.DecodeFromBytes(data[offset:])
		if err != nil {
			return err
		}
		b.Nexthops = append(b.Nexthops, nh)

		offset += nh.Len()
		if len(data) < offset {
			break
		}
	}

	return nil
}
1171372
func Decode(im *imageserver.Image) (image.Image, error) {
	nim, format, err := image.Decode(bytes.NewReader(im.Data))
	if err != nil {
		return nil, &imageserver.ImageError{Message: err.Error()}
	}
	if format != im.Format {
		return nil, &imageserver.ImageError{Message: fmt.Sprintf("decoded format \"%s\" does not match image format \"%s\"", format, im.Format)}
	}
	return nim, nil
}
1276039
func newDataFileReaderBytes(buf []byte, datumReader DatumReader) (reader *DataFileReader, err error) {
	if len(buf) < len(magic) || !bytes.Equal(magic, buf[0:4]) {
		return nil, NotAvroFile
	}

	dec := NewBinaryDecoder(buf)
	blockDecoder := NewBinaryDecoder(nil)
	reader = &DataFileReader{
		data:         buf,
		dec:          dec,
		blockDecoder: blockDecoder,
		datum:        datumReader,
	}

	if reader.header, err = readObjFileHeader(dec); err != nil {
		return nil, err
	}

	schema, err := ParseSchema(string(reader.header.Meta[schemaKey]))
	if err != nil {
		return nil, err
	}
	reader.datum.SetSchema(schema)
	reader.block = &DataBlock{}

	if reader.hasNextBlock() {
		if err := reader.NextBlock(); err != nil {
			return nil, err
		}
	}

	return reader, nil
}
1295841
func ParseBytes(s []byte, options ...Option) (*Token, error) {
	return Parse(bytes.NewReader(s), options...)
}
769844
func NewBytesResponse(status int, body []byte) *http.Response {
	return &http.Response{
		Status:        strconv.Itoa(status),
		StatusCode:    status,
		Body:          NewRespBodyFromBytes(body),
		Header:        http.Header{},
		ContentLength: -1,
	}
}
1109925
func Int2Bytes(v int) []byte {
	ret := make([]byte, 4)
	Int2BytesTo(v, ret)
	return ret
}
1138408
func NewDigestFromBytes(alg Algorithm, p []byte) Digest {
	return Digest(fmt.Sprintf("%s:%x", alg, p))
}
368971
func int2bytes(val uint64) []byte {
	data, j := make([]byte, 8), -1
	for i := 0; i < 8; i++ {
		shift := uint64((7 - i) * 8)
		data[i] = byte((val & (0xff << shift)) >> shift)

		if j == -1 && data[i] != 0 {
			j = i
		}
	}

	if j != -1 {
		return data[j:]
	}
	return data[:1]
}
586302
func cloneBytes(v []byte) []byte {
	var clone = make([]byte, len(v))
	copy(clone, v)
	return clone
}
81735
func NewBytes(value []byte, opts BytesOptions) Bytes {
	if opts == nil {
		opts = defaultBytesOptions
	}
	b := &bytesRef{
		opts:  opts,
		value: value,
	}
	b.SetFinalizer(b)
	// NB(r): Tracking objects causes interface allocation
	// so avoid if we are not performing any leak detection.
	if leakDetectionEnabled() {
		b.TrackObject(b.value)
	}
	return b
}
1272442
func EncodeBytes(val interface{}) ([]byte, error) {
	buf := new(bytes.Buffer)
	e := NewEncoder(buf)
	if err := e.Encode(val); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}