// ReadBytes reads a bytes value. Returns a decoded value and an error if it occurs.
346012
func (bd *BinaryDecoder) ReadBytes() ([]byte, error) {
	//TODO make something with these if's!!
	if err := checkEOF(bd.buf, bd.pos, 1); err != nil {
		return nil, EOF
	}
	length, err := bd.ReadLong()
	if err != nil {
		return nil, err
	}
	if length < 0 {
		return nil, NegativeBytesLength
	}
	if err = checkEOF(bd.buf, bd.pos, int(length)); err != nil {
		return nil, EOF
	}

	bytes := make([]byte, length)
	copy(bytes[:], bd.buf[bd.pos:bd.pos+length])
	bd.pos += length
	return bytes, err
}
691013
func ReadBytes(data []byte, opts ...Option) (Node, error) {
	return Read(bytes.NewBuffer(data), opts...)
}
66860
func readBytes(dst []byte, r io.Reader) error {
	offset := 0
	remaining := len(dst)
	if remaining == 0 {
		// Nothing left to read
		return nil
	}
	for {
		n, err := r.Read(dst[offset:])
		offset += n
		remaining -= n
		if remaining == 0 {
			return nil
		}
		if err != nil {
			return err
		}
	}
}
1186744
func DecodeBytes(b []byte, val interface{}) error {
	r := bytes.NewReader(b)
	d := NewDecoder(r)
	return d.Decode(val)
}
1295937
func (rd *bitReader) readBits(n int) (int, error) {
	if n <= 0 {
		return 0, nil
	}

	retval, bits := 0, rd.bits
	for {
		if bits == 0 {
			if rd.head == rd.limit {
				if err := rd.refill(); err != nil {
					return 0, err
				}
			}
			bits, rd.current = 8, rd.buffer[rd.head]
			rd.head++
		}

		if n <= bits {
			retval <<= uint(n)
			retval |= int(rd.current >> uint(8-n))
			rd.current <<= uint(n)
			bits -= n
			rd.bits = bits
			return retval, nil
		} else {
			retval <<= uint(bits)
			retval |= int(rd.current >> uint(8-bits))
			n -= bits
			bits = 0
		}
	}
}
1086575
func (s *Image) SetBytes(v []byte) *Image {
	s.Bytes = v
	return s
}
1343629
func readBytes(conn *bufio.Reader, bytes *[]byte, length int) (b byte, err error) {
	newbytes := make([]byte, length)
	n, err := conn.Read(newbytes)
	if n != length {
		fmt.Errorf("%d bytes read instead of %d", n, length)
	} else if err != nil {
		return
	}
	*bytes = append(*bytes, newbytes...)
	b = (*bytes)[len(*bytes)-1]
	return
}
41219
func (d *Decoder) readBytes(delim byte) (line []byte, err error) {
	line, err = d.r.ReadBytes(delim)
	if d.raw {
		d.buf = append(d.buf, line...)
	}
	d.n += len(line)
	return
}
74694
func (r *importReader) readByte() byte {
	c, err := r.b.ReadByte()
	if err == nil {
		r.buf = append(r.buf, c)
		if c == 0 {
			err = errNUL
		}
	}
	if err != nil {
		if err == io.EOF {
			r.eof = true
		} else if r.err == nil {
			r.err = err
		}
		c = 0
	}
	return c
}
628557
func (f Files) GetBytes(name string) []byte {
	v, ok := f[name]
	if !ok {
		return []byte{}
	}
	return v
}
168565
func (s *Session) GetBytes(ctx context.Context, key string) []byte {
	val := s.Get(ctx, key)
	b, ok := val.([]byte)
	if !ok {
		return nil
	}
	return b
}
858024
func (rd *bitReader) readByte() (int, error) {
	if rd.head == rd.limit {
		if err := rd.refill(); err != nil {
			return 0, err
		}
	}

	rd.bits = 0
	rd.current = rd.buffer[rd.head]
	rd.head++
	return int(rd.current), nil
}
437093
func (r *View) ReadByte() (byte, error) {
	chunk := r.chunkBytes()
	if len(chunk) == 0 {
		return 0, io.EOF
	}
	r.Skip(1)
	return chunk[0], nil
}
938350
func readBytesCopy(data []byte, pos int, size int) ([]byte, int, bool) {
	if pos+size-1 >= len(data) {
		return nil, 0, false
	}
	result := make([]byte, size)
	copy(result, data[pos:pos+size])
	return result, pos + size, true
}
237237
func (r *reader) readBitsAsBytes(n uint32) []byte {
	tmp := make([]byte, 0)
	for n >= 8 {
		tmp = append(tmp, r.readByte())
		n -= 8
	}
	if n > 0 {
		tmp = append(tmp, byte(r.readBits(n)))
	}
	return tmp
}
358544
func (r *buffer) ReadByte() (byte, error) {
	if r.off == r.size {
		return 0, io.EOF
	}
	b := r.data[r.off]
	r.off++
	return b, nil
}
26096
func (d *decoder) readBits(n uint) uint32 {
	for d.nbits < n {
		d.v <<= 8
		d.v |= uint32(d.buf[d.off])
		d.off++
		d.nbits += 8
	}
	d.nbits -= n
	rv := d.v >> d.nbits
	d.v &^= rv << d.nbits
	return rv
}