package gojay

import 

// DecodeArray reads the next JSON-encoded value from the decoder's input (io.Reader)
// and stores it in the value pointed to by v.
//
// v must implement UnmarshalerJSONArray.
//
// See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func ( *Decoder) ( UnmarshalerJSONArray) error {
	if .isPooled == 1 {
		panic(InvalidUsagePooledDecoderError("Invalid usage of pooled decoder"))
	}
	,  := .decodeArray()
	return 
}
func ( *Decoder) ( UnmarshalerJSONArray) (int, error) {
	// remember last array index in case of nested arrays
	 := .arrayIndex
	.arrayIndex = 0
	defer func() {
		.arrayIndex = 
	}()
	for ; .cursor < .length || .read(); .cursor++ {
		switch .data[.cursor] {
		case ' ', '\n', '\t', '\r', ',':
			continue
		case '[':
			.cursor = .cursor + 1
			// array is open, char is not space start readings
			for .nextChar() != 0 {
				// closing array
				if .data[.cursor] == ']' {
					.cursor = .cursor + 1
					return .cursor, nil
				}
				// calling unmarshall function for each element of the slice
				 := .UnmarshalJSONArray()
				if  != nil {
					return 0, 
				}
				.arrayIndex++
			}
			return 0, .raiseInvalidJSONErr(.cursor)
		case 'n':
			// is null
			.cursor++
			 := .assertNull()
			if  != nil {
				return 0, 
			}
			return .cursor, nil
		case '{', '"', 'f', 't', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			// can't unmarshall to struct
			// we skip array and set Error
			.err = .makeInvalidUnmarshalErr()
			 := .skipData()
			if  != nil {
				return 0, 
			}
			return .cursor, nil
		default:
			return 0, .raiseInvalidJSONErr(.cursor)
		}
	}
	return 0, .raiseInvalidJSONErr(.cursor)
}
func ( *Decoder) ( interface{}) (int, error) {
	// remember last array index in case of nested arrays
	 := .arrayIndex
	.arrayIndex = 0
	defer func() {
		.arrayIndex = 
	}()
	 := reflect.ValueOf()
	 := .Type()
	if .Kind() != reflect.Ptr || .Elem().Kind() != reflect.Ptr {
		.err = ErrUnmarshalPtrExpected
		return 0, .err
	}
	// not an array not an error, but do not know what to do
	// do not check syntax
	for ; .cursor < .length || .read(); .cursor++ {
		switch .data[.cursor] {
		case ' ', '\n', '\t', '\r', ',':
			continue
		case '[':
			.cursor = .cursor + 1
			// create our new type
			 := .Elem()
			 := reflect.New(.Type().Elem())
			var  UnmarshalerJSONArray
			var  bool
			if ,  = .Interface().(UnmarshalerJSONArray); ! {
				.err = .makeInvalidUnmarshalErr((UnmarshalerJSONArray)(nil))
				return 0, .err
			}
			// array is open, char is not space start readings
			for .nextChar() != 0 {
				// closing array
				if .data[.cursor] == ']' {
					.Set()
					.cursor = .cursor + 1
					return .cursor, nil
				}
				// calling unmarshall function for each element of the slice
				 := .UnmarshalJSONArray()
				if  != nil {
					return 0, 
				}
				.arrayIndex++
			}
			return 0, .raiseInvalidJSONErr(.cursor)
		case 'n':
			// is null
			.cursor++
			 := .assertNull()
			if  != nil {
				return 0, 
			}
			return .cursor, nil
		case '{', '"', 'f', 't', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			// can't unmarshall to struct
			// we skip array and set Error
			.err = .makeInvalidUnmarshalErr((UnmarshalerJSONArray)(nil))
			 := .skipData()
			if  != nil {
				return 0, 
			}
			return .cursor, nil
		default:
			return 0, .raiseInvalidJSONErr(.cursor)
		}
	}
	return 0, .raiseInvalidJSONErr(.cursor)
}

func ( *Decoder) () (int, error) {
	var  = 1
	var  = 0
	// var stringOpen byte = 0
	for  := .cursor;  < .length || .read(); ++ {
		switch .data[] {
		case ']':
			++
			// everything is closed return
			if  ==  {
				// add char to object data
				return  + 1, nil
			}
		case '[':
			++
		case '"':
			++
			var  bool
			var  = true
			for ;  < .length || .read(); ++ {
				if .data[] != '"' {
					continue
				}
				if .data[-1] != '\\' || (! && !) {
					break
				} else {
					 = false
				}
				if  {
					 = false
				}
				// loop backward and count how many anti slash found
				// to see if string is effectively escaped
				 := 0
				for  :=  - 1;  > 0; -- {
					if .data[] != '\\' {
						break
					}
					++
				}
				// is pair number of slashes, quote is not escaped
				if &1 == 0 {
					break
				}
				 = true
			}
		default:
			continue
		}
	}
	return 0, .raiseInvalidJSONErr(.cursor)
}

// DecodeArrayFunc is a func type implementing UnmarshalerJSONArray.
// Use it to cast a `func(*Decoder) error` to Unmarshal an array on the fly.

type DecodeArrayFunc func(*Decoder) error

// UnmarshalJSONArray implements UnmarshalerJSONArray.
func ( DecodeArrayFunc) ( *Decoder) error {
	return ()
}

// IsNil implements UnmarshalerJSONArray.
func ( DecodeArrayFunc) () bool {
	return  == nil
}

// Add Values functions

// AddArray decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
func ( *Decoder) ( UnmarshalerJSONArray) error {
	return .Array()
}

// AddArrayNull decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
func ( *Decoder) ( interface{}) error {
	return .ArrayNull()
}

// Array decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
func ( *Decoder) ( UnmarshalerJSONArray) error {
	,  := .decodeArray()
	if  != nil {
		return 
	}
	.cursor = 
	.called |= 1
	return nil
}

// ArrayNull decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
// v should be a pointer to an UnmarshalerJSONArray,
// if `null` value is encountered in JSON, it will leave the value v untouched,
// else it will create a new instance of the UnmarshalerJSONArray behind v.
func ( *Decoder) ( interface{}) error {
	,  := .decodeArrayNull()
	if  != nil {
		return 
	}
	.cursor = 
	.called |= 1
	return nil
}

// Index returns the index of an array being decoded.
func ( *Decoder) () int {
	return .arrayIndex
}