// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package pool

import (
	
	
	
)

type BytesReader struct {
	s []byte
	i int
}

func ( []byte) *BytesReader {
	return &BytesReader{
		s: ,
	}
}

func ( *BytesReader) ( []byte) {
	.s = 
	.i = 0
}

func ( *BytesReader) () int {
	return len(.s) - .i
}

func ( *BytesReader) () []byte {
	return .s[.i:]
}

func ( *BytesReader) ( []byte) ( int,  error) {
	if .i >= len(.s) {
		return 0, io.EOF
	}
	 = copy(, .s[.i:])
	.i += 
	return
}

func ( *BytesReader) () (byte, error) {
	if .i >= len(.s) {
		return 0, io.EOF
	}
	 := .s[.i]
	.i++
	return , nil
}

func ( *BytesReader) () error {
	if .i <= 0 {
		return errors.New("UnreadByte: at beginning of slice")
	}
	.i--
	return nil
}

func ( *BytesReader) ( byte) ([]byte, error) {
	if  := bytes.IndexByte(.s[.i:], );  >= 0 {
		++
		 := .s[.i : .i+]
		.i += 
		return , nil
	}

	 := .s[.i:]
	.i = len(.s)
	return , io.EOF
}

func ( *BytesReader) ( func(byte) bool) ([]byte, error) {
	for ,  := range .s[.i:] {
		if !() {
			++
			 := .s[.i : .i+]
			.i += 
			return , nil
		}
	}

	 := .s[.i:]
	.i = len(.s)
	return , io.EOF
}

func ( *BytesReader) ( int) (int, error) {
	,  := .ReadN()
	return len(), 
}

func ( *BytesReader) ( int) ([]byte, error) {
	 := 
	if  > len(.s) {
		 = len(.s)
	}

	 := .s[.i : .i+]
	.i += 
	if  >  {
		return , io.EOF
	}
	return , nil
}

func ( *BytesReader) () ([]byte, error) {
	 := make([]byte, len(.s)-.i)
	copy(, .s[.i:])
	.i = len(.s)
	return , nil
}

func ( *BytesReader) () ([]byte, error) {
	 := .s[.i:]
	.i = len(.s)
	return , nil
}