// DO NOT EDIT!
// Code generated by ffjson <https://github.com/pquerna/ffjson>
// source: recording.go
// DO NOT EDIT!

package recording

import (
	"bytes"
	"errors"
	"fmt"

	fflib "github.com/pquerna/ffjson/fflib/v1"
)

func (mj *ChunkInfo) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	if mj == nil {
		buf.WriteString("null")
		return buf.Bytes(), nil
	}
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *ChunkInfo) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
	if mj == nil {
		buf.WriteString("null")
		return nil
	}
	var err error
	var obj []byte
	_ = obj
	_ = err
	buf.WriteString(`{"chunkId":`)
	fflib.FormatBits2(buf, uint64(mj.CurrentChunk), 10, mj.CurrentChunk < 0)
	buf.WriteString(`,"availableSince":`)
	fflib.FormatBits2(buf, uint64(mj.AvailableSince), 10, mj.AvailableSince < 0)
	buf.WriteString(`,"nextAvailableChunk":`)
	fflib.FormatBits2(buf, uint64(mj.NextUpdate), 10, mj.NextUpdate < 0)
	buf.WriteString(`,"keyFrameId":`)
	fflib.FormatBits2(buf, uint64(mj.CurrentKeyFrame), 10, mj.CurrentKeyFrame < 0)
	buf.WriteString(`,"nextChunkId":`)
	fflib.FormatBits2(buf, uint64(mj.NextChunk), 10, mj.NextChunk < 0)
	buf.WriteString(`,"endStartupChunkId":`)
	fflib.FormatBits2(buf, uint64(mj.EndStartupChunk), 10, mj.EndStartupChunk < 0)
	buf.WriteString(`,"startGameChunkId":`)
	fflib.FormatBits2(buf, uint64(mj.StartGameChunk), 10, mj.StartGameChunk < 0)
	buf.WriteString(`,"endGameChunkId":`)
	fflib.FormatBits2(buf, uint64(mj.EndGameChunk), 10, mj.EndGameChunk < 0)
	buf.WriteString(`,"duration":`)
	fflib.FormatBits2(buf, uint64(mj.Duration), 10, mj.Duration < 0)
	buf.WriteByte('}')
	return nil
}

const (
	ffj_t_ChunkInfobase = iota
	ffj_t_ChunkInfono_such_key

	ffj_t_ChunkInfo_CurrentChunk

	ffj_t_ChunkInfo_AvailableSince

	ffj_t_ChunkInfo_NextUpdate

	ffj_t_ChunkInfo_CurrentKeyFrame

	ffj_t_ChunkInfo_NextChunk

	ffj_t_ChunkInfo_EndStartupChunk

	ffj_t_ChunkInfo_StartGameChunk

	ffj_t_ChunkInfo_EndGameChunk

	ffj_t_ChunkInfo_Duration
)

var ffj_key_ChunkInfo_CurrentChunk = []byte("chunkId")

var ffj_key_ChunkInfo_AvailableSince = []byte("availableSince")

var ffj_key_ChunkInfo_NextUpdate = []byte("nextAvailableChunk")

var ffj_key_ChunkInfo_CurrentKeyFrame = []byte("keyFrameId")

var ffj_key_ChunkInfo_NextChunk = []byte("nextChunkId")

var ffj_key_ChunkInfo_EndStartupChunk = []byte("endStartupChunkId")

var ffj_key_ChunkInfo_StartGameChunk = []byte("startGameChunkId")

var ffj_key_ChunkInfo_EndGameChunk = []byte("endGameChunkId")

var ffj_key_ChunkInfo_Duration = []byte("duration")

func (uj *ChunkInfo) UnmarshalJSON(input []byte) error {
	fs := fflib.NewFFLexer(input)
	return uj.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}

func (uj *ChunkInfo) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
	var err error = nil
	currentKey := ffj_t_ChunkInfobase
	_ = currentKey
	tok := fflib.FFTok_init
	wantedTok := fflib.FFTok_init

mainparse:
	for {
		tok = fs.Scan()
		//	println(fmt.Sprintf("debug: tok: %v  state: %v", tok, state))
		if tok == fflib.FFTok_error {
			goto tokerror
		}

		switch state {

		case fflib.FFParse_map_start:
			if tok != fflib.FFTok_left_bracket {
				wantedTok = fflib.FFTok_left_bracket
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_key
			continue

		case fflib.FFParse_after_value:
			if tok == fflib.FFTok_comma {
				state = fflib.FFParse_want_key
			} else if tok == fflib.FFTok_right_bracket {
				goto done
			} else {
				wantedTok = fflib.FFTok_comma
				goto wrongtokenerror
			}

		case fflib.FFParse_want_key:
			// json {} ended. goto exit. woo.
			if tok == fflib.FFTok_right_bracket {
				goto done
			}
			if tok != fflib.FFTok_string {
				wantedTok = fflib.FFTok_string
				goto wrongtokenerror
			}

			kn := fs.Output.Bytes()
			if len(kn) <= 0 {
				// "" case. hrm.
				currentKey = ffj_t_ChunkInfono_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			} else {
				switch kn[0] {

				case 'a':

					if bytes.Equal(ffj_key_ChunkInfo_AvailableSince, kn) {
						currentKey = ffj_t_ChunkInfo_AvailableSince
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'c':

					if bytes.Equal(ffj_key_ChunkInfo_CurrentChunk, kn) {
						currentKey = ffj_t_ChunkInfo_CurrentChunk
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'd':

					if bytes.Equal(ffj_key_ChunkInfo_Duration, kn) {
						currentKey = ffj_t_ChunkInfo_Duration
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'e':

					if bytes.Equal(ffj_key_ChunkInfo_EndStartupChunk, kn) {
						currentKey = ffj_t_ChunkInfo_EndStartupChunk
						state = fflib.FFParse_want_colon
						goto mainparse

					} else if bytes.Equal(ffj_key_ChunkInfo_EndGameChunk, kn) {
						currentKey = ffj_t_ChunkInfo_EndGameChunk
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'k':

					if bytes.Equal(ffj_key_ChunkInfo_CurrentKeyFrame, kn) {
						currentKey = ffj_t_ChunkInfo_CurrentKeyFrame
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'n':

					if bytes.Equal(ffj_key_ChunkInfo_NextUpdate, kn) {
						currentKey = ffj_t_ChunkInfo_NextUpdate
						state = fflib.FFParse_want_colon
						goto mainparse

					} else if bytes.Equal(ffj_key_ChunkInfo_NextChunk, kn) {
						currentKey = ffj_t_ChunkInfo_NextChunk
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 's':

					if bytes.Equal(ffj_key_ChunkInfo_StartGameChunk, kn) {
						currentKey = ffj_t_ChunkInfo_StartGameChunk
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				}

				if fflib.SimpleLetterEqualFold(ffj_key_ChunkInfo_Duration, kn) {
					currentKey = ffj_t_ChunkInfo_Duration
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_ChunkInfo_EndGameChunk, kn) {
					currentKey = ffj_t_ChunkInfo_EndGameChunk
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_ChunkInfo_StartGameChunk, kn) {
					currentKey = ffj_t_ChunkInfo_StartGameChunk
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_ChunkInfo_EndStartupChunk, kn) {
					currentKey = ffj_t_ChunkInfo_EndStartupChunk
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_ChunkInfo_NextChunk, kn) {
					currentKey = ffj_t_ChunkInfo_NextChunk
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_ChunkInfo_CurrentKeyFrame, kn) {
					currentKey = ffj_t_ChunkInfo_CurrentKeyFrame
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_ChunkInfo_NextUpdate, kn) {
					currentKey = ffj_t_ChunkInfo_NextUpdate
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_ChunkInfo_AvailableSince, kn) {
					currentKey = ffj_t_ChunkInfo_AvailableSince
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_ChunkInfo_CurrentChunk, kn) {
					currentKey = ffj_t_ChunkInfo_CurrentChunk
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				currentKey = ffj_t_ChunkInfono_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			}

		case fflib.FFParse_want_colon:
			if tok != fflib.FFTok_colon {
				wantedTok = fflib.FFTok_colon
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_value
			continue
		case fflib.FFParse_want_value:

			if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
				switch currentKey {

				case ffj_t_ChunkInfo_CurrentChunk:
					goto handle_CurrentChunk

				case ffj_t_ChunkInfo_AvailableSince:
					goto handle_AvailableSince

				case ffj_t_ChunkInfo_NextUpdate:
					goto handle_NextUpdate

				case ffj_t_ChunkInfo_CurrentKeyFrame:
					goto handle_CurrentKeyFrame

				case ffj_t_ChunkInfo_NextChunk:
					goto handle_NextChunk

				case ffj_t_ChunkInfo_EndStartupChunk:
					goto handle_EndStartupChunk

				case ffj_t_ChunkInfo_StartGameChunk:
					goto handle_StartGameChunk

				case ffj_t_ChunkInfo_EndGameChunk:
					goto handle_EndGameChunk

				case ffj_t_ChunkInfo_Duration:
					goto handle_Duration

				case ffj_t_ChunkInfono_such_key:
					err = fs.SkipField(tok)
					if err != nil {
						return fs.WrapErr(err)
					}
					state = fflib.FFParse_after_value
					goto mainparse
				}
			} else {
				goto wantedvalue
			}
		}
	}

handle_CurrentChunk:

	/* handler: uj.CurrentChunk type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.CurrentChunk = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_AvailableSince:

	/* handler: uj.AvailableSince type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.AvailableSince = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_NextUpdate:

	/* handler: uj.NextUpdate type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.NextUpdate = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_CurrentKeyFrame:

	/* handler: uj.CurrentKeyFrame type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.CurrentKeyFrame = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_NextChunk:

	/* handler: uj.NextChunk type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.NextChunk = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_EndStartupChunk:

	/* handler: uj.EndStartupChunk type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.EndStartupChunk = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_StartGameChunk:

	/* handler: uj.StartGameChunk type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.StartGameChunk = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_EndGameChunk:

	/* handler: uj.EndGameChunk type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.EndGameChunk = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_Duration:

	/* handler: uj.Duration type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.Duration = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

wantedvalue:
	return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
wrongtokenerror:
	return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
tokerror:
	if fs.BigError != nil {
		return fs.WrapErr(fs.BigError)
	}
	err = fs.Error.ToError()
	if err != nil {
		return fs.WrapErr(err)
	}
	panic("ffjson-generated: unreachable, please report bug.")
done:
	return nil
}

func (mj *GameInfo) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	if mj == nil {
		buf.WriteString("null")
		return buf.Bytes(), nil
	}
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *GameInfo) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
	if mj == nil {
		buf.WriteString("null")
		return nil
	}
	var err error
	var obj []byte
	_ = obj
	_ = err
	buf.WriteString(`{"Platform":`)
	fflib.WriteJsonString(buf, string(mj.Platform))
	buf.WriteString(`,"Version":`)
	fflib.WriteJsonString(buf, string(mj.Version))
	buf.WriteString(`,"GameID":`)
	fflib.WriteJsonString(buf, string(mj.GameID))
	buf.WriteString(`,"EncryptionKey":`)
	fflib.WriteJsonString(buf, string(mj.EncryptionKey))
	buf.WriteString(`,"RecordTime":`)

	{

		obj, err = mj.RecordTime.MarshalJSON()
		if err != nil {
			return err
		}
		buf.Write(obj)

	}
	buf.WriteByte('}')
	return nil
}

const (
	ffj_t_GameInfobase = iota
	ffj_t_GameInfono_such_key

	ffj_t_GameInfo_Platform

	ffj_t_GameInfo_Version

	ffj_t_GameInfo_GameID

	ffj_t_GameInfo_EncryptionKey

	ffj_t_GameInfo_RecordTime
)

var ffj_key_GameInfo_Platform = []byte("Platform")

var ffj_key_GameInfo_Version = []byte("Version")

var ffj_key_GameInfo_GameID = []byte("GameID")

var ffj_key_GameInfo_EncryptionKey = []byte("EncryptionKey")

var ffj_key_GameInfo_RecordTime = []byte("RecordTime")

func (uj *GameInfo) UnmarshalJSON(input []byte) error {
	fs := fflib.NewFFLexer(input)
	return uj.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}

func (uj *GameInfo) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
	var err error = nil
	currentKey := ffj_t_GameInfobase
	_ = currentKey
	tok := fflib.FFTok_init
	wantedTok := fflib.FFTok_init

mainparse:
	for {
		tok = fs.Scan()
		//	println(fmt.Sprintf("debug: tok: %v  state: %v", tok, state))
		if tok == fflib.FFTok_error {
			goto tokerror
		}

		switch state {

		case fflib.FFParse_map_start:
			if tok != fflib.FFTok_left_bracket {
				wantedTok = fflib.FFTok_left_bracket
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_key
			continue

		case fflib.FFParse_after_value:
			if tok == fflib.FFTok_comma {
				state = fflib.FFParse_want_key
			} else if tok == fflib.FFTok_right_bracket {
				goto done
			} else {
				wantedTok = fflib.FFTok_comma
				goto wrongtokenerror
			}

		case fflib.FFParse_want_key:
			// json {} ended. goto exit. woo.
			if tok == fflib.FFTok_right_bracket {
				goto done
			}
			if tok != fflib.FFTok_string {
				wantedTok = fflib.FFTok_string
				goto wrongtokenerror
			}

			kn := fs.Output.Bytes()
			if len(kn) <= 0 {
				// "" case. hrm.
				currentKey = ffj_t_GameInfono_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			} else {
				switch kn[0] {

				case 'E':

					if bytes.Equal(ffj_key_GameInfo_EncryptionKey, kn) {
						currentKey = ffj_t_GameInfo_EncryptionKey
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'G':

					if bytes.Equal(ffj_key_GameInfo_GameID, kn) {
						currentKey = ffj_t_GameInfo_GameID
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'P':

					if bytes.Equal(ffj_key_GameInfo_Platform, kn) {
						currentKey = ffj_t_GameInfo_Platform
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'R':

					if bytes.Equal(ffj_key_GameInfo_RecordTime, kn) {
						currentKey = ffj_t_GameInfo_RecordTime
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'V':

					if bytes.Equal(ffj_key_GameInfo_Version, kn) {
						currentKey = ffj_t_GameInfo_Version
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				}

				if fflib.SimpleLetterEqualFold(ffj_key_GameInfo_RecordTime, kn) {
					currentKey = ffj_t_GameInfo_RecordTime
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_GameInfo_EncryptionKey, kn) {
					currentKey = ffj_t_GameInfo_EncryptionKey
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.SimpleLetterEqualFold(ffj_key_GameInfo_GameID, kn) {
					currentKey = ffj_t_GameInfo_GameID
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_GameInfo_Version, kn) {
					currentKey = ffj_t_GameInfo_Version
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.SimpleLetterEqualFold(ffj_key_GameInfo_Platform, kn) {
					currentKey = ffj_t_GameInfo_Platform
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				currentKey = ffj_t_GameInfono_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			}

		case fflib.FFParse_want_colon:
			if tok != fflib.FFTok_colon {
				wantedTok = fflib.FFTok_colon
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_value
			continue
		case fflib.FFParse_want_value:

			if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
				switch currentKey {

				case ffj_t_GameInfo_Platform:
					goto handle_Platform

				case ffj_t_GameInfo_Version:
					goto handle_Version

				case ffj_t_GameInfo_GameID:
					goto handle_GameID

				case ffj_t_GameInfo_EncryptionKey:
					goto handle_EncryptionKey

				case ffj_t_GameInfo_RecordTime:
					goto handle_RecordTime

				case ffj_t_GameInfono_such_key:
					err = fs.SkipField(tok)
					if err != nil {
						return fs.WrapErr(err)
					}
					state = fflib.FFParse_after_value
					goto mainparse
				}
			} else {
				goto wantedvalue
			}
		}
	}

handle_Platform:

	/* handler: uj.Platform type=string kind=string quoted=false*/

	{

		{
			if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
				return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
			}
		}

		if tok == fflib.FFTok_null {

		} else {

			outBuf := fs.Output.Bytes()

			uj.Platform = string(string(outBuf))

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_Version:

	/* handler: uj.Version type=string kind=string quoted=false*/

	{

		{
			if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
				return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
			}
		}

		if tok == fflib.FFTok_null {

		} else {

			outBuf := fs.Output.Bytes()

			uj.Version = string(string(outBuf))

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_GameID:

	/* handler: uj.GameID type=string kind=string quoted=false*/

	{

		{
			if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
				return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
			}
		}

		if tok == fflib.FFTok_null {

		} else {

			outBuf := fs.Output.Bytes()

			uj.GameID = string(string(outBuf))

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_EncryptionKey:

	/* handler: uj.EncryptionKey type=string kind=string quoted=false*/

	{

		{
			if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
				return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
			}
		}

		if tok == fflib.FFTok_null {

		} else {

			outBuf := fs.Output.Bytes()

			uj.EncryptionKey = string(string(outBuf))

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_RecordTime:

	/* handler: uj.RecordTime type=time.Time kind=struct quoted=false*/

	{
		if tok == fflib.FFTok_null {

			state = fflib.FFParse_after_value
			goto mainparse
		}

		tbuf, err := fs.CaptureField(tok)
		if err != nil {
			return fs.WrapErr(err)
		}

		err = uj.RecordTime.UnmarshalJSON(tbuf)
		if err != nil {
			return fs.WrapErr(err)
		}
		state = fflib.FFParse_after_value
	}

	state = fflib.FFParse_after_value
	goto mainparse

wantedvalue:
	return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
wrongtokenerror:
	return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
tokerror:
	if fs.BigError != nil {
		return fs.WrapErr(fs.BigError)
	}
	err = fs.Error.ToError()
	if err != nil {
		return fs.WrapErr(err)
	}
	panic("ffjson-generated: unreachable, please report bug.")
done:
	return nil
}

func (mj *Recording) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	if mj == nil {
		buf.WriteString("null")
		return buf.Bytes(), nil
	}
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *Recording) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
	if mj == nil {
		buf.WriteString("null")
		return nil
	}
	var err error
	var obj []byte
	_ = obj
	_ = err
	buf.WriteString(`{}`)
	return nil
}

const (
	ffj_t_Recordingbase = iota
	ffj_t_Recordingno_such_key
)

func (uj *Recording) UnmarshalJSON(input []byte) error {
	fs := fflib.NewFFLexer(input)
	return uj.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}

func (uj *Recording) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
	var err error = nil
	currentKey := ffj_t_Recordingbase
	_ = currentKey
	tok := fflib.FFTok_init
	wantedTok := fflib.FFTok_init

mainparse:
	for {
		tok = fs.Scan()
		//	println(fmt.Sprintf("debug: tok: %v  state: %v", tok, state))
		if tok == fflib.FFTok_error {
			goto tokerror
		}

		switch state {

		case fflib.FFParse_map_start:
			if tok != fflib.FFTok_left_bracket {
				wantedTok = fflib.FFTok_left_bracket
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_key
			continue

		case fflib.FFParse_after_value:
			if tok == fflib.FFTok_comma {
				state = fflib.FFParse_want_key
			} else if tok == fflib.FFTok_right_bracket {
				goto done
			} else {
				wantedTok = fflib.FFTok_comma
				goto wrongtokenerror
			}

		case fflib.FFParse_want_key:
			// json {} ended. goto exit. woo.
			if tok == fflib.FFTok_right_bracket {
				goto done
			}
			if tok != fflib.FFTok_string {
				wantedTok = fflib.FFTok_string
				goto wrongtokenerror
			}

			kn := fs.Output.Bytes()
			if len(kn) <= 0 {
				// "" case. hrm.
				currentKey = ffj_t_Recordingno_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			} else {
				switch kn[0] {

				}

				currentKey = ffj_t_Recordingno_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			}

		case fflib.FFParse_want_colon:
			if tok != fflib.FFTok_colon {
				wantedTok = fflib.FFTok_colon
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_value
			continue
		case fflib.FFParse_want_value:

			if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
				switch currentKey {

				case ffj_t_Recordingno_such_key:
					err = fs.SkipField(tok)
					if err != nil {
						return fs.WrapErr(err)
					}
					state = fflib.FFParse_after_value
					goto mainparse
				}
			} else {
				goto wantedvalue
			}
		}
	}

wantedvalue:
	return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
wrongtokenerror:
	return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
tokerror:
	if fs.BigError != nil {
		return fs.WrapErr(fs.BigError)
	}
	err = fs.Error.ToError()
	if err != nil {
		return fs.WrapErr(err)
	}
	panic("ffjson-generated: unreachable, please report bug.")
done:
	return nil
}

func (mj *recordingHeader) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	if mj == nil {
		buf.WriteString("null")
		return buf.Bytes(), nil
	}
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *recordingHeader) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
	if mj == nil {
		buf.WriteString("null")
		return nil
	}
	var err error
	var obj []byte
	_ = obj
	_ = err
	buf.WriteString(`{"GameMetadata":`)

	{

		err = mj.GameMetadata.MarshalJSONBuf(buf)
		if err != nil {
			return err
		}

	}
	buf.WriteString(`,"FirstChunkInfo":`)

	{

		err = mj.FirstChunkInfo.MarshalJSONBuf(buf)
		if err != nil {
			return err
		}

	}
	buf.WriteString(`,"LastChunkInfo":`)

	{

		err = mj.LastChunkInfo.MarshalJSONBuf(buf)
		if err != nil {
			return err
		}

	}
	/* Falling back. type=map[int]recording.segment kind=map */
	buf.WriteString(`,"KeyFrameMap":`)
	err = buf.Encode(mj.KeyFrameMap)
	if err != nil {
		return err
	}
	/* Falling back. type=map[int]recording.segment kind=map */
	buf.WriteString(`,"ChunkMap":`)
	err = buf.Encode(mj.ChunkMap)
	if err != nil {
		return err
	}
	buf.WriteString(`,"Info":`)

	{

		err = mj.Info.MarshalJSONBuf(buf)
		if err != nil {
			return err
		}

	}
	buf.WriteString(`,"UserMetadata":`)

	{

		err = mj.UserMetadata.MarshalJSONBuf(buf)
		if err != nil {
			return err
		}

	}
	if mj.IsComplete {
		buf.WriteString(`,"IsComplete":true`)
	} else {
		buf.WriteString(`,"IsComplete":false`)
	}
	buf.WriteByte('}')
	return nil
}

const (
	ffj_t_recordingHeaderbase = iota
	ffj_t_recordingHeaderno_such_key

	ffj_t_recordingHeader_GameMetadata

	ffj_t_recordingHeader_FirstChunkInfo

	ffj_t_recordingHeader_LastChunkInfo

	ffj_t_recordingHeader_KeyFrameMap

	ffj_t_recordingHeader_ChunkMap

	ffj_t_recordingHeader_Info

	ffj_t_recordingHeader_UserMetadata

	ffj_t_recordingHeader_IsComplete
)

var ffj_key_recordingHeader_GameMetadata = []byte("GameMetadata")

var ffj_key_recordingHeader_FirstChunkInfo = []byte("FirstChunkInfo")

var ffj_key_recordingHeader_LastChunkInfo = []byte("LastChunkInfo")

var ffj_key_recordingHeader_KeyFrameMap = []byte("KeyFrameMap")

var ffj_key_recordingHeader_ChunkMap = []byte("ChunkMap")

var ffj_key_recordingHeader_Info = []byte("Info")

var ffj_key_recordingHeader_UserMetadata = []byte("UserMetadata")

var ffj_key_recordingHeader_IsComplete = []byte("IsComplete")

func (uj *recordingHeader) UnmarshalJSON(input []byte) error {
	fs := fflib.NewFFLexer(input)
	return uj.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}

func (uj *recordingHeader) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
	var err error = nil
	currentKey := ffj_t_recordingHeaderbase
	_ = currentKey
	tok := fflib.FFTok_init
	wantedTok := fflib.FFTok_init

mainparse:
	for {
		tok = fs.Scan()
		//	println(fmt.Sprintf("debug: tok: %v  state: %v", tok, state))
		if tok == fflib.FFTok_error {
			goto tokerror
		}

		switch state {

		case fflib.FFParse_map_start:
			if tok != fflib.FFTok_left_bracket {
				wantedTok = fflib.FFTok_left_bracket
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_key
			continue

		case fflib.FFParse_after_value:
			if tok == fflib.FFTok_comma {
				state = fflib.FFParse_want_key
			} else if tok == fflib.FFTok_right_bracket {
				goto done
			} else {
				wantedTok = fflib.FFTok_comma
				goto wrongtokenerror
			}

		case fflib.FFParse_want_key:
			// json {} ended. goto exit. woo.
			if tok == fflib.FFTok_right_bracket {
				goto done
			}
			if tok != fflib.FFTok_string {
				wantedTok = fflib.FFTok_string
				goto wrongtokenerror
			}

			kn := fs.Output.Bytes()
			if len(kn) <= 0 {
				// "" case. hrm.
				currentKey = ffj_t_recordingHeaderno_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			} else {
				switch kn[0] {

				case 'C':

					if bytes.Equal(ffj_key_recordingHeader_ChunkMap, kn) {
						currentKey = ffj_t_recordingHeader_ChunkMap
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'F':

					if bytes.Equal(ffj_key_recordingHeader_FirstChunkInfo, kn) {
						currentKey = ffj_t_recordingHeader_FirstChunkInfo
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'G':

					if bytes.Equal(ffj_key_recordingHeader_GameMetadata, kn) {
						currentKey = ffj_t_recordingHeader_GameMetadata
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'I':

					if bytes.Equal(ffj_key_recordingHeader_Info, kn) {
						currentKey = ffj_t_recordingHeader_Info
						state = fflib.FFParse_want_colon
						goto mainparse

					} else if bytes.Equal(ffj_key_recordingHeader_IsComplete, kn) {
						currentKey = ffj_t_recordingHeader_IsComplete
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'K':

					if bytes.Equal(ffj_key_recordingHeader_KeyFrameMap, kn) {
						currentKey = ffj_t_recordingHeader_KeyFrameMap
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'L':

					if bytes.Equal(ffj_key_recordingHeader_LastChunkInfo, kn) {
						currentKey = ffj_t_recordingHeader_LastChunkInfo
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'U':

					if bytes.Equal(ffj_key_recordingHeader_UserMetadata, kn) {
						currentKey = ffj_t_recordingHeader_UserMetadata
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				}

				if fflib.EqualFoldRight(ffj_key_recordingHeader_IsComplete, kn) {
					currentKey = ffj_t_recordingHeader_IsComplete
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_recordingHeader_UserMetadata, kn) {
					currentKey = ffj_t_recordingHeader_UserMetadata
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.SimpleLetterEqualFold(ffj_key_recordingHeader_Info, kn) {
					currentKey = ffj_t_recordingHeader_Info
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_recordingHeader_ChunkMap, kn) {
					currentKey = ffj_t_recordingHeader_ChunkMap
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_recordingHeader_KeyFrameMap, kn) {
					currentKey = ffj_t_recordingHeader_KeyFrameMap
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_recordingHeader_LastChunkInfo, kn) {
					currentKey = ffj_t_recordingHeader_LastChunkInfo
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_recordingHeader_FirstChunkInfo, kn) {
					currentKey = ffj_t_recordingHeader_FirstChunkInfo
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.SimpleLetterEqualFold(ffj_key_recordingHeader_GameMetadata, kn) {
					currentKey = ffj_t_recordingHeader_GameMetadata
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				currentKey = ffj_t_recordingHeaderno_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			}

		case fflib.FFParse_want_colon:
			if tok != fflib.FFTok_colon {
				wantedTok = fflib.FFTok_colon
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_value
			continue
		case fflib.FFParse_want_value:

			if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
				switch currentKey {

				case ffj_t_recordingHeader_GameMetadata:
					goto handle_GameMetadata

				case ffj_t_recordingHeader_FirstChunkInfo:
					goto handle_FirstChunkInfo

				case ffj_t_recordingHeader_LastChunkInfo:
					goto handle_LastChunkInfo

				case ffj_t_recordingHeader_KeyFrameMap:
					goto handle_KeyFrameMap

				case ffj_t_recordingHeader_ChunkMap:
					goto handle_ChunkMap

				case ffj_t_recordingHeader_Info:
					goto handle_Info

				case ffj_t_recordingHeader_UserMetadata:
					goto handle_UserMetadata

				case ffj_t_recordingHeader_IsComplete:
					goto handle_IsComplete

				case ffj_t_recordingHeaderno_such_key:
					err = fs.SkipField(tok)
					if err != nil {
						return fs.WrapErr(err)
					}
					state = fflib.FFParse_after_value
					goto mainparse
				}
			} else {
				goto wantedvalue
			}
		}
	}

handle_GameMetadata:

	/* handler: uj.GameMetadata type=recording.segment kind=struct quoted=false*/

	{
		if tok == fflib.FFTok_null {

			state = fflib.FFParse_after_value
			goto mainparse
		}

		err = uj.GameMetadata.UnmarshalJSONFFLexer(fs, fflib.FFParse_want_key)
		if err != nil {
			return err
		}
		state = fflib.FFParse_after_value
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_FirstChunkInfo:

	/* handler: uj.FirstChunkInfo type=recording.ChunkInfo kind=struct quoted=false*/

	{
		if tok == fflib.FFTok_null {

			state = fflib.FFParse_after_value
			goto mainparse
		}

		err = uj.FirstChunkInfo.UnmarshalJSONFFLexer(fs, fflib.FFParse_want_key)
		if err != nil {
			return err
		}
		state = fflib.FFParse_after_value
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_LastChunkInfo:

	/* handler: uj.LastChunkInfo type=recording.ChunkInfo kind=struct quoted=false*/

	{
		if tok == fflib.FFTok_null {

			state = fflib.FFParse_after_value
			goto mainparse
		}

		err = uj.LastChunkInfo.UnmarshalJSONFFLexer(fs, fflib.FFParse_want_key)
		if err != nil {
			return err
		}
		state = fflib.FFParse_after_value
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_KeyFrameMap:

	/* handler: uj.KeyFrameMap type=map[int]recording.segment kind=map quoted=false*/

	{

		{
			if tok != fflib.FFTok_left_bracket && tok != fflib.FFTok_null {
				return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for ", tok))
			}
		}

		if tok == fflib.FFTok_null {
			uj.KeyFrameMap = nil
		} else {

			uj.KeyFrameMap = make(map[int]segment, 0)

			wantVal := true

			for {

				var k int

				var tmp_uj__KeyFrameMap segment

				tok = fs.Scan()
				if tok == fflib.FFTok_error {
					goto tokerror
				}
				if tok == fflib.FFTok_right_bracket {
					break
				}

				if tok == fflib.FFTok_comma {
					if wantVal == true {
						// TODO(pquerna): this isn't an ideal error message, this handles
						// things like [,,,] as an array value.
						return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
					}
					continue
				} else {
					wantVal = true
				}

				/* handler: k type=int kind=int quoted=false*/

				{
					if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
						return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
					}
				}

				{

					if tok == fflib.FFTok_null {

					} else {

						tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

						if err != nil {
							return fs.WrapErr(err)
						}

						k = int(tval)

					}
				}

				// Expect ':' after key
				tok = fs.Scan()
				if tok != fflib.FFTok_colon {
					return fs.WrapErr(fmt.Errorf("wanted colon token, but got token: %v", tok))
				}

				tok = fs.Scan()
				/* handler: tmp_uj__KeyFrameMap type=recording.segment kind=struct quoted=false*/

				{
					if tok == fflib.FFTok_null {

						state = fflib.FFParse_after_value
						goto mainparse
					}

					err = tmp_uj__KeyFrameMap.UnmarshalJSONFFLexer(fs, fflib.FFParse_want_key)
					if err != nil {
						return err
					}
					state = fflib.FFParse_after_value
				}

				uj.KeyFrameMap[k] = tmp_uj__KeyFrameMap

				wantVal = false
			}

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_ChunkMap:

	/* handler: uj.ChunkMap type=map[int]recording.segment kind=map quoted=false*/

	{

		{
			if tok != fflib.FFTok_left_bracket && tok != fflib.FFTok_null {
				return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for ", tok))
			}
		}

		if tok == fflib.FFTok_null {
			uj.ChunkMap = nil
		} else {

			uj.ChunkMap = make(map[int]segment, 0)

			wantVal := true

			for {

				var k int

				var tmp_uj__ChunkMap segment

				tok = fs.Scan()
				if tok == fflib.FFTok_error {
					goto tokerror
				}
				if tok == fflib.FFTok_right_bracket {
					break
				}

				if tok == fflib.FFTok_comma {
					if wantVal == true {
						// TODO(pquerna): this isn't an ideal error message, this handles
						// things like [,,,] as an array value.
						return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
					}
					continue
				} else {
					wantVal = true
				}

				/* handler: k type=int kind=int quoted=false*/

				{
					if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
						return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
					}
				}

				{

					if tok == fflib.FFTok_null {

					} else {

						tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

						if err != nil {
							return fs.WrapErr(err)
						}

						k = int(tval)

					}
				}

				// Expect ':' after key
				tok = fs.Scan()
				if tok != fflib.FFTok_colon {
					return fs.WrapErr(fmt.Errorf("wanted colon token, but got token: %v", tok))
				}

				tok = fs.Scan()
				/* handler: tmp_uj__ChunkMap type=recording.segment kind=struct quoted=false*/

				{
					if tok == fflib.FFTok_null {

						state = fflib.FFParse_after_value
						goto mainparse
					}

					err = tmp_uj__ChunkMap.UnmarshalJSONFFLexer(fs, fflib.FFParse_want_key)
					if err != nil {
						return err
					}
					state = fflib.FFParse_after_value
				}

				uj.ChunkMap[k] = tmp_uj__ChunkMap

				wantVal = false
			}

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_Info:

	/* handler: uj.Info type=recording.GameInfo kind=struct quoted=false*/

	{
		if tok == fflib.FFTok_null {

			state = fflib.FFParse_after_value
			goto mainparse
		}

		err = uj.Info.UnmarshalJSONFFLexer(fs, fflib.FFParse_want_key)
		if err != nil {
			return err
		}
		state = fflib.FFParse_after_value
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_UserMetadata:

	/* handler: uj.UserMetadata type=recording.segment kind=struct quoted=false*/

	{
		if tok == fflib.FFTok_null {

			state = fflib.FFParse_after_value
			goto mainparse
		}

		err = uj.UserMetadata.UnmarshalJSONFFLexer(fs, fflib.FFParse_want_key)
		if err != nil {
			return err
		}
		state = fflib.FFParse_after_value
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_IsComplete:

	/* handler: uj.IsComplete type=bool kind=bool quoted=false*/

	{
		if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
		}
	}

	{
		if tok == fflib.FFTok_null {

		} else {
			tmpb := fs.Output.Bytes()

			if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {

				uj.IsComplete = true

			} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {

				uj.IsComplete = false

			} else {
				err = errors.New("unexpected bytes for true/false value")
				return fs.WrapErr(err)
			}

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

wantedvalue:
	return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
wrongtokenerror:
	return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
tokerror:
	if fs.BigError != nil {
		return fs.WrapErr(fs.BigError)
	}
	err = fs.Error.ToError()
	if err != nil {
		return fs.WrapErr(err)
	}
	panic("ffjson-generated: unreachable, please report bug.")
done:
	return nil
}

func (mj *segment) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	if mj == nil {
		buf.WriteString("null")
		return buf.Bytes(), nil
	}
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *segment) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
	if mj == nil {
		buf.WriteString("null")
		return nil
	}
	var err error
	var obj []byte
	_ = obj
	_ = err
	buf.WriteString(`{"Position":`)
	fflib.FormatBits2(buf, uint64(mj.Position), 10, mj.Position < 0)
	buf.WriteString(`,"Length":`)
	fflib.FormatBits2(buf, uint64(mj.Length), 10, mj.Length < 0)
	buf.WriteByte('}')
	return nil
}

const (
	ffj_t_segmentbase = iota
	ffj_t_segmentno_such_key

	ffj_t_segment_Position

	ffj_t_segment_Length
)

var ffj_key_segment_Position = []byte("Position")

var ffj_key_segment_Length = []byte("Length")

func (uj *segment) UnmarshalJSON(input []byte) error {
	fs := fflib.NewFFLexer(input)
	return uj.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}

func (uj *segment) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
	var err error = nil
	currentKey := ffj_t_segmentbase
	_ = currentKey
	tok := fflib.FFTok_init
	wantedTok := fflib.FFTok_init

mainparse:
	for {
		tok = fs.Scan()
		//	println(fmt.Sprintf("debug: tok: %v  state: %v", tok, state))
		if tok == fflib.FFTok_error {
			goto tokerror
		}

		switch state {

		case fflib.FFParse_map_start:
			if tok != fflib.FFTok_left_bracket {
				wantedTok = fflib.FFTok_left_bracket
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_key
			continue

		case fflib.FFParse_after_value:
			if tok == fflib.FFTok_comma {
				state = fflib.FFParse_want_key
			} else if tok == fflib.FFTok_right_bracket {
				goto done
			} else {
				wantedTok = fflib.FFTok_comma
				goto wrongtokenerror
			}

		case fflib.FFParse_want_key:
			// json {} ended. goto exit. woo.
			if tok == fflib.FFTok_right_bracket {
				goto done
			}
			if tok != fflib.FFTok_string {
				wantedTok = fflib.FFTok_string
				goto wrongtokenerror
			}

			kn := fs.Output.Bytes()
			if len(kn) <= 0 {
				// "" case. hrm.
				currentKey = ffj_t_segmentno_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			} else {
				switch kn[0] {

				case 'L':

					if bytes.Equal(ffj_key_segment_Length, kn) {
						currentKey = ffj_t_segment_Length
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				case 'P':

					if bytes.Equal(ffj_key_segment_Position, kn) {
						currentKey = ffj_t_segment_Position
						state = fflib.FFParse_want_colon
						goto mainparse
					}

				}

				if fflib.SimpleLetterEqualFold(ffj_key_segment_Length, kn) {
					currentKey = ffj_t_segment_Length
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				if fflib.EqualFoldRight(ffj_key_segment_Position, kn) {
					currentKey = ffj_t_segment_Position
					state = fflib.FFParse_want_colon
					goto mainparse
				}

				currentKey = ffj_t_segmentno_such_key
				state = fflib.FFParse_want_colon
				goto mainparse
			}

		case fflib.FFParse_want_colon:
			if tok != fflib.FFTok_colon {
				wantedTok = fflib.FFTok_colon
				goto wrongtokenerror
			}
			state = fflib.FFParse_want_value
			continue
		case fflib.FFParse_want_value:

			if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
				switch currentKey {

				case ffj_t_segment_Position:
					goto handle_Position

				case ffj_t_segment_Length:
					goto handle_Length

				case ffj_t_segmentno_such_key:
					err = fs.SkipField(tok)
					if err != nil {
						return fs.WrapErr(err)
					}
					state = fflib.FFParse_after_value
					goto mainparse
				}
			} else {
				goto wantedvalue
			}
		}
	}

handle_Position:

	/* handler: uj.Position type=int64 kind=int64 quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int64", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.Position = int64(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

handle_Length:

	/* handler: uj.Length type=int kind=int quoted=false*/

	{
		if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
			return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
		}
	}

	{

		if tok == fflib.FFTok_null {

		} else {

			tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)

			if err != nil {
				return fs.WrapErr(err)
			}

			uj.Length = int(tval)

		}
	}

	state = fflib.FFParse_after_value
	goto mainparse

wantedvalue:
	return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
wrongtokenerror:
	return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
tokerror:
	if fs.BigError != nil {
		return fs.WrapErr(fs.BigError)
	}
	err = fs.Error.ToError()
	if err != nil {
		return fs.WrapErr(err)
	}
	panic("ffjson-generated: unreachable, please report bug.")
done:
	return nil
}
