package gojay

// EmbeddedJSON is a raw encoded JSON value.
// It can be used to delay JSON decoding or precompute a JSON encoding.
type EmbeddedJSON []byte

func ( *Decoder) ( *EmbeddedJSON) error {
	var  error
	if  == nil {
		return InvalidUnmarshalError("Invalid nil pointer given")
	}
	var  int
	for ; .cursor < .length || .read(); .cursor++ {
		switch .data[.cursor] {
		case ' ', '\n', '\t', '\r', ',':
			continue
		// is null
		case 'n':
			 = .cursor
			.cursor++
			 := .assertNull()
			if  != nil {
				return 
			}
		case 't':
			 = .cursor
			.cursor++
			 := .assertTrue()
			if  != nil {
				return 
			}
		// is false
		case 'f':
			 = .cursor
			.cursor++
			 := .assertFalse()
			if  != nil {
				return 
			}
		// is an object
		case '{':
			 = .cursor
			.cursor = .cursor + 1
			.cursor,  = .skipObject()
		// is string
		case '"':
			 = .cursor
			.cursor = .cursor + 1
			 = .skipString() // why no new dec.cursor in result?
		// is array
		case '[':
			 = .cursor
			.cursor = .cursor + 1
			.cursor,  = .skipArray()
		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-':
			 = .cursor
			.cursor,  = .skipNumber()
		}
		break
	}
	if  == nil {
		if .cursor-1 >=  {
			* = append(*, .data[:.cursor]...)
		}
		.called |= 1
	}
	return 
}

// AddEmbeddedJSON adds an EmbeddedsJSON to the value pointed by v.
// It can be used to delay JSON decoding or precompute a JSON encoding.
func ( *Decoder) ( *EmbeddedJSON) error {
	return .EmbeddedJSON()
}

// EmbeddedJSON adds an EmbeddedsJSON to the value pointed by v.
// It can be used to delay JSON decoding or precompute a JSON encoding.
func ( *Decoder) ( *EmbeddedJSON) error {
	 := .decodeEmbeddedJSON()
	if  != nil {
		return 
	}
	.called |= 1
	return nil
}