package jx

import (
	
	
)

// Writer writes json tokens to underlying buffer.
//
// Zero value is valid.
type Writer struct {
	Buf    []byte // underlying buffer
	stream *streamState
}

// Write implements io.Writer.
func ( *Writer) ( []byte) ( int,  error) {
	if .stream != nil {
		return 0, errStreaming
	}
	.Buf = append(.Buf, ...)
	return len(), nil
}

// WriteTo implements io.WriterTo.
func ( *Writer) ( io.Writer) ( int64,  error) {
	if .stream != nil {
		return 0, errStreaming
	}
	,  := .Write(.Buf)
	return int64(), 
}

// String returns string of underlying buffer.
func ( Writer) () string {
	.stream.mustNotBeStreaming()
	return string(.Buf)
}

// Reset resets underlying buffer.
//
// If w is in streaming mode, it is reset to non-streaming mode.
func ( *Writer) () {
	.Buf = .Buf[:0]
	.stream = nil
}

// ResetWriter resets underlying buffer and sets output writer.
func ( *Writer) ( io.Writer) {
	.Buf = .Buf[:0]
	if .stream == nil {
		.stream = newStreamState()
	}
	.stream.Reset()
}

// Grow grows the underlying buffer.
//
// Calls (*bytes.Buffer).Grow(n int) on w.Buf.
func ( *Writer) ( int) {
	 := bytes.NewBuffer(.Buf)
	.Grow()
	.Buf = .Bytes()
}

// byte writes a single byte.
func ( *Writer) ( byte) ( bool) {
	if .stream == nil {
		.Buf = append(.Buf, )
		return false
	}
	return writeStreamBytes(, )
}

func ( *Writer) (,  byte) bool {
	if .stream == nil {
		.Buf = append(.Buf, , )
		return false
	}
	return writeStreamBytes(, , )
}

// RawStr writes string as raw json.
func ( *Writer) ( string) bool {
	return .rawStr()
}

func ( *Writer) ( string) bool {
	return writeStreamByteseq(, )
}

// Raw writes byte slice as raw json.
func ( *Writer) ( []byte) bool {
	return writeStreamByteseq(, )
}

// Null writes null.
func ( *Writer) () bool {
	return writeStreamByteseq(, "null")
}

// True writes true.
func ( *Writer) () bool {
	return writeStreamByteseq(, "true")
}

// False writes false.
func ( *Writer) () bool {
	return writeStreamByteseq(, "false")
}

// Bool encodes boolean.
func ( *Writer) ( bool) bool {
	if  {
		return .True()
	}
	return .False()
}

// ObjStart writes object start.
func ( *Writer) () bool {
	return .byte('{')
}

// FieldStart encodes field name and writes colon.
func ( *Writer) ( string) bool {
	return .Str() ||
		.byte(':')
}

// ObjEnd writes end of object token.
func ( *Writer) () bool {
	return .byte('}')
}

// ArrStart writes start of array.
func ( *Writer) () bool {
	return .byte('[')
}

// ArrEnd writes end of array.
func ( *Writer) () bool {
	return .byte(']')
}

// Comma writes comma.
func ( *Writer) () bool {
	return .byte(',')
}