package jx

import (
	
	
)

// Next gets Type of relatively next json element
func ( *Decoder) () Type {
	,  := .next()
	if  == nil {
		.unread()
	}
	return types[]
}

var spaceSet = [256]byte{
	' ': 1, '\n': 1, '\t': 1, '\r': 1,
}

func ( *Decoder) ( byte) ( error) {
	for {
		 := .buf[.head:.tail]
		for ,  := range  {
			switch spaceSet[] {
			default:
				if  !=  {
					return badToken(, .offset()+)
				}
				.head +=  + 1
				return nil
			case 1:
				continue
			}
		}
		if  = .read();  != nil {
			if  == io.EOF {
				return io.ErrUnexpectedEOF
			}
			return 
		}
	}
}

// more is next but io.EOF is unexpected.
func ( *Decoder) () (byte, error) {
	,  := .next()
	if  == io.EOF {
		 = io.ErrUnexpectedEOF
	}
	return , 
}

// next reads next non-whitespace token or error.
func ( *Decoder) () (byte, error) {
	for {
		 := .buf[.head:.tail]
		for ,  := range  {
			switch spaceSet[] {
			default:
				.head +=  + 1
				return , nil
			case 1:
				continue
			}
		}
		if  := .read();  != nil {
			return 0, 
		}
	}
}

// peek returns next byte without advancing.
func ( *Decoder) () (byte, error) {
	if .head == .tail {
		if  := .read();  != nil {
			return 0, 
		}
	}
	 := .buf[.head]
	return , nil
}

func ( *Decoder) () (byte, error) {
	if .head == .tail {
		 := .read()
		if  == io.EOF {
			 = io.ErrUnexpectedEOF
		}
		if  != nil {
			return 0, 
		}
	}
	 := .buf[.head]
	.head++
	return , nil
}

func ( *Decoder) () error {
	if .reader == nil {
		.head = .tail
		return io.EOF
	}

	,  := .reader.Read(.buf)
	switch  {
	case nil:
	case io.EOF:
		if  > 0 {
			break
		}
		fallthrough
	default:
		return 
	}

	.streamOffset += .tail
	.head = 0
	.tail = 
	return nil
}

func ( *Decoder) ( int) error {
	if .reader == nil {
		.head = .tail
		return io.ErrUnexpectedEOF
	}

	if  :=  - len(.buf);  > 0 {
		.buf = append(.buf, make([]byte, )...)
	}
	,  := io.ReadAtLeast(.reader, .buf, )
	if  != nil {
		if  == io.EOF &&  == 0 {
			return io.ErrUnexpectedEOF
		}
		return 
	}

	.streamOffset += .tail
	.head = 0
	.tail = 
	return nil
}

func ( *Decoder) () { .head-- }

func ( *Decoder) ( *[4]byte) error {
	if  := .buf[.head:.tail]; len() >= len() {
		.head += copy([:], [:4])
		return nil
	}

	 := copy([:], .buf[.head:.tail])
	if  := .readAtLeast(len() - );  != nil {
		return 
	}
	.head += copy([:], .buf[.head:.tail])
	return nil
}

func ( [4]byte,  uint32,  int) error {
	 := uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24
	 := bits.TrailingZeros32(^) / 8
	return badToken([], +)
}