package gojay

import (
	
	
)

// DecodeObject 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 UnmarshalerJSONObject.
//
// See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func ( *Decoder) ( UnmarshalerJSONObject) error {
	if .isPooled == 1 {
		panic(InvalidUsagePooledDecoderError("Invalid usage of pooled decoder"))
	}
	,  := .decodeObject()
	return 
}
func ( *Decoder) ( UnmarshalerJSONObject) (int, error) {
	 := .NKeys()
	for ; .cursor < .length || .read(); .cursor++ {
		switch .data[.cursor] {
		case ' ', '\n', '\t', '\r', ',':
		case '{':
			.cursor = .cursor + 1
			// if keys is zero we will parse all keys
			// we run two loops for micro optimization
			if  == 0 {
				for .cursor < .length || .read() {
					, ,  := .nextKey()
					if  != nil {
						return 0, 
					} else if  {
						return .cursor, nil
					}
					 = .UnmarshalJSONObject(, )
					if  != nil {
						.err = 
						return 0, 
					} else if .called&1 == 0 {
						 := .skipData()
						if  != nil {
							return 0, 
						}
					} else {
						.keysDone++
					}
					.called &= 0
				}
			} else {
				for (.cursor < .length || .read()) && .keysDone <  {
					, ,  := .nextKey()
					if  != nil {
						return 0, 
					} else if  {
						return .cursor, nil
					}
					 = .UnmarshalJSONObject(, )
					if  != nil {
						.err = 
						return 0, 
					} else if .called&1 == 0 {
						 := .skipData()
						if  != nil {
							return 0, 
						}
					} else {
						.keysDone++
					}
					.called &= 0
				}
			}
			// will get to that point when keysDone is not lower than keys anymore
			// in that case, we make sure cursor goes to the end of object, but we skip
			// unmarshalling
			if .child&1 != 0 {
				,  := .skipObject()
				.cursor = 
				return .cursor, 
			}
			return .cursor, nil
		case 'n':
			.cursor++
			 := .assertNull()
			if  != nil {
				return 0, 
			}
			return .cursor, nil
		default:
			// can't unmarshal to struct
			.err = .makeInvalidUnmarshalErr()
			 := .skipData()
			if  != nil {
				return 0, 
			}
			return .cursor, nil
		}
	}
	return 0, .raiseInvalidJSONErr(.cursor)
}

func ( *Decoder) ( interface{}) (int, error) {
	// make sure the value is a pointer
	 := reflect.ValueOf()
	 := .Type()
	if .Kind() != reflect.Ptr || .Elem().Kind() != reflect.Ptr {
		.err = ErrUnmarshalPtrExpected
		return 0, .err
	}
	for ; .cursor < .length || .read(); .cursor++ {
		switch .data[.cursor] {
		case ' ', '\n', '\t', '\r', ',':
		case '{':
			 := .Elem()
			 := reflect.New(.Type().Elem())
			.Set()
			var  UnmarshalerJSONObject
			var  bool
			if ,  = .Interface().(UnmarshalerJSONObject); ! {
				.err = .makeInvalidUnmarshalErr((UnmarshalerJSONObject)(nil))
				return 0, .err
			}
			 := .NKeys()
			.cursor = .cursor + 1
			// if keys is zero we will parse all keys
			// we run two loops for micro optimization
			if  == 0 {
				for .cursor < .length || .read() {
					, ,  := .nextKey()
					if  != nil {
						return 0, 
					} else if  {
						return .cursor, nil
					}
					 = .UnmarshalJSONObject(, )
					if  != nil {
						.err = 
						return 0, 
					} else if .called&1 == 0 {
						 := .skipData()
						if  != nil {
							return 0, 
						}
					} else {
						.keysDone++
					}
					.called &= 0
				}
			} else {
				for (.cursor < .length || .read()) && .keysDone <  {
					, ,  := .nextKey()
					if  != nil {
						return 0, 
					} else if  {
						return .cursor, nil
					}
					 = .UnmarshalJSONObject(, )
					if  != nil {
						.err = 
						return 0, 
					} else if .called&1 == 0 {
						 := .skipData()
						if  != nil {
							return 0, 
						}
					} else {
						.keysDone++
					}
					.called &= 0
				}
			}
			// will get to that point when keysDone is not lower than keys anymore
			// in that case, we make sure cursor goes to the end of object, but we skip
			// unmarshalling
			if .child&1 != 0 {
				,  := .skipObject()
				.cursor = 
				return .cursor, 
			}
			return .cursor, nil
		case 'n':
			.cursor++
			 := .assertNull()
			if  != nil {
				return 0, 
			}
			return .cursor, nil
		default:
			// can't unmarshal to struct
			.err = .makeInvalidUnmarshalErr((UnmarshalerJSONObject)(nil))
			 := .skipData()
			if  != nil {
				return 0, 
			}
			return .cursor, nil
		}
	}
	return 0, .raiseInvalidJSONErr(.cursor)
}

func ( *Decoder) () (int, error) {
	var  = 1
	var  = 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)
}

func ( *Decoder) () (string, bool, error) {
	for ; .cursor < .length || .read(); .cursor++ {
		switch .data[.cursor] {
		case ' ', '\n', '\t', '\r', ',':
			continue
		case '"':
			.cursor = .cursor + 1
			, ,  := .getString()
			if  != nil {
				return "", false, 
			}
			var  byte
			for ; .cursor < .length || .read(); .cursor++ {
				if .data[.cursor] == ':' {
					 |= 1
					break
				}
			}
			if &1 != 0 {
				.cursor++
				 := .data[ : -1]
				return *(*string)(unsafe.Pointer(&)), false, nil
			}
			return "", false, .raiseInvalidJSONErr(.cursor)
		case '}':
			.cursor = .cursor + 1
			return "", true, nil
		default:
			// can't unmarshall to struct
			return "", false, .raiseInvalidJSONErr(.cursor)
		}
	}
	return "", false, .raiseInvalidJSONErr(.cursor)
}

func ( *Decoder) () error {
	for ; .cursor < .length || .read(); .cursor++ {
		switch .data[.cursor] {
		case ' ', '\n', '\t', '\r', ',':
			continue
		// is null
		case 'n':
			.cursor++
			 := .assertNull()
			if  != nil {
				return 
			}
			return nil
		case 't':
			.cursor++
			 := .assertTrue()
			if  != nil {
				return 
			}
			return nil
		// is false
		case 'f':
			.cursor++
			 := .assertFalse()
			if  != nil {
				return 
			}
			return nil
		// is an object
		case '{':
			.cursor = .cursor + 1
			,  := .skipObject()
			.cursor = 
			return 
		// is string
		case '"':
			.cursor = .cursor + 1
			 := .skipString()
			return 
		// is array
		case '[':
			.cursor = .cursor + 1
			,  := .skipArray()
			.cursor = 
			return 
		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-':
			,  := .skipNumber()
			.cursor = 
			return 
		}
		return .raiseInvalidJSONErr(.cursor)
	}
	return .raiseInvalidJSONErr(.cursor)
}

// DecodeObjectFunc is a func type implementing UnmarshalerJSONObject.
// Use it to cast a `func(*Decoder, k string) error` to Unmarshal an object on the fly.
type DecodeObjectFunc func(*Decoder, string) error

// UnmarshalJSONObject implements UnmarshalerJSONObject.
func ( DecodeObjectFunc) ( *Decoder,  string) error {
	return (, )
}

// NKeys implements UnmarshalerJSONObject.
func ( DecodeObjectFunc) () int {
	return 0
}

// Add Values functions

// AddObject decodes the JSON value within an object or an array to a UnmarshalerJSONObject.
func ( *Decoder) ( UnmarshalerJSONObject) error {
	return .Object()
}

// AddObjectNull decodes the JSON value within an object or an array to a UnmarshalerJSONObject.
func ( *Decoder) ( interface{}) error {
	return .ObjectNull()
}

// Object decodes the JSON value within an object or an array to a UnmarshalerJSONObject.
func ( *Decoder) ( UnmarshalerJSONObject) error {
	 := .keysDone
	 := .child
	.keysDone = 0
	.called = 0
	.child |= 1
	,  := .decodeObject()
	if  != nil {
		return 
	}
	.cursor = 
	.keysDone = 
	.child = 
	.called |= 1
	return nil
}

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