package jx

import (
	

	
)

type rawReader struct {
	// internal buffer, may be reference to *Decoder.buf.
	buf []byte
	// if true, buf is reference to  *Decoder.buf.
	captured bool
	orig     io.Reader
}

func ( *rawReader) ( []byte) ( int,  error) {
	if .captured {
		// Make a copy.
		.buf = append([]byte(nil), .buf...)
		.captured = false
	}
	,  = .orig.Read()
	if  > 0 {
		.buf = append(.buf, [:]...)
	}
	return , 
}

// Raw is like Skip(), but saves and returns skipped value as raw json.
//
// Do not retain returned value, it references underlying buffer.
func ( *Decoder) () (Raw, error) {
	 := .head
	if  := .reader;  != nil {
		 := &rawReader{
			buf:      .buf[:.tail],
			captured: true,
			orig:     ,
		}
		.reader = 
		defer func() {
			.reader = 
		}()

		if  := .Skip();  != nil {
			return nil, errors.Wrap(, "skip")
		}

		 := .tail - .head
		 := .buf
		 = [:len()-]
		return , nil
	}

	if  := .Skip();  != nil {
		return nil, errors.Wrap(, "skip")
	}

	return .buf[:.head], nil
}

// RawAppend is Raw that appends saved raw json value to buf.
func ( *Decoder) ( Raw) (Raw, error) {
	,  := .Raw()
	if  != nil {
		return nil, 
	}
	return append(, ...), 
}

// Raw json value.
type Raw []byte

// Type of Raw json value.
func ( Raw) () Type {
	 := Decoder{buf: , tail: len()}
	return .Next()
}

func ( Raw) () string { return string() }