func (j *ServicesState) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
	if j == nil {
		buf.WriteString("null")
		return nil
	}
	var err error
	var obj []byte
	_ = obj
	_ = err
	buf.WriteString(`{"Servers":`)
	err = buf.Encode(j.Servers)
	if err != nil {
		return err
	}
	buf.WriteString(`,"LastChanged":`)
	{
		obj, err = j.LastChanged.MarshalJSON()
		if err != nil {
			return err
		}
		buf.Write(obj)
	}
	buf.WriteString(`,"ClusterName":`)
	fflib.WriteJsonString(buf, string(j.ClusterName))
	buf.WriteString(`,"Hostname":`)
	fflib.WriteJsonString(buf, string(j.Hostname))
	buf.WriteByte('}')
	return nil
}
MarshalJSONBuf marshal buff to json - template
package catalog
import (
	"bytes"
	"fmt"
	"github.com/NinesStack/sidecar/service"
	fflib "github.com/pquerna/ffjson/fflib/v1"
)
func (j *ChangeEvent) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	if j == nil {
		buf.WriteString("null")
		return buf.Bytes(), nil
	}
	err := j.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (j *ChangeEvent) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
	if j == nil {
		buf.WriteString("null")
		return nil
	}
	var err error
	var obj []byte
	_ = obj
	_ = err
	buf.WriteString(`{"Service":`)
	{
		err = j.Service.MarshalJSONBuf(buf)
		if err != nil {
			return err
		}
	}
	buf.WriteString(`,"PreviousStatus":`)
	fflib.FormatBits2(buf, uint64(j.PreviousStatus), 10, j.PreviousStatus < 0)
	buf.WriteString(`,"Time":`)
	{
		obj, err = j.Time.MarshalJSON()
		if err != nil {
			return err
		}
		buf.Write(obj)
	}
	buf.WriteByte('}')
	return nil
}
const (
	ffjtChangeEventbase = iota
	ffjtChangeEventnosuchkey
	ffjtChangeEventService
	ffjtChangeEventPreviousStatus
	ffjtChangeEventTime
)
var ffjKeyChangeEventService = []byte("Service")
var ffjKeyChangeEventPreviousStatus = []byte("PreviousStatus")
var ffjKeyChangeEventTime = []byte("Time")
func (j *ChangeEvent) UnmarshalJSON(input []byte) error {
	fs := fflib.NewFFLexer(input)
	return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}
func (j *ChangeEvent) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
	var err error
	currentKey := ffjtChangeEventbase
	_ = currentKey
	tok := fflib.FFTok_init
	wantedTok := fflib.FFTok_init
mainparse:
	for {
		tok = fs.Scan()
		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:
			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 {
				currentKey = ffjtChangeEventnosuchkey
				state = fflib.FFParse_want_colon
				goto mainparse
			} else {
				switch kn[0] {
				case 'P':
					if bytes.Equal(ffjKeyChangeEventPreviousStatus, kn) {
						currentKey = ffjtChangeEventPreviousStatus
						state = fflib.FFParse_want_colon
						goto mainparse
					}
				case 'S':
					if bytes.Equal(ffjKeyChangeEventService, kn) {
						currentKey = ffjtChangeEventService
						state = fflib.FFParse_want_colon
						goto mainparse
					}
				case 'T':
					if bytes.Equal(ffjKeyChangeEventTime, kn) {
						currentKey = ffjtChangeEventTime
						state = fflib.FFParse_want_colon
						goto mainparse
					}
				}
				if fflib.SimpleLetterEqualFold(ffjKeyChangeEventTime, kn) {
					currentKey = ffjtChangeEventTime
					state = fflib.FFParse_want_colon
					goto mainparse
				}
				if fflib.EqualFoldRight(ffjKeyChangeEventPreviousStatus, kn) {
					currentKey = ffjtChangeEventPreviousStatus
					state = fflib.FFParse_want_colon
					goto mainparse
				}
				if fflib.EqualFoldRight(ffjKeyChangeEventService, kn) {
					currentKey = ffjtChangeEventService
					state = fflib.FFParse_want_colon
					goto mainparse
				}
				currentKey = ffjtChangeEventnosuchkey
				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 ffjtChangeEventService:
					goto handle_Service
				case ffjtChangeEventPreviousStatus:
					goto handle_PreviousStatus
				case ffjtChangeEventTime:
					goto handle_Time
				case ffjtChangeEventnosuchkey:
					err = fs.SkipField(tok)
					if err != nil {
						return fs.WrapErr(err)
					}
					state = fflib.FFParse_after_value
					goto mainparse
				}
			} else {
				goto wantedvalue
			}
		}
	}
handle_Service:
	{
		if tok == fflib.FFTok_null {
		} else {
			err = j.Service.UnmarshalJSONFFLexer(fs, fflib.FFParse_want_key)
			if err != nil {
				return err
			}
		}
		state = fflib.FFParse_after_value
	}
	state = fflib.FFParse_after_value
	goto mainparse
handle_PreviousStatus:
	{
		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)
			}
			j.PreviousStatus = int(tval)
		}
	}
	state = fflib.FFParse_after_value
	goto mainparse
handle_Time:
	{
		if tok == fflib.FFTok_null {
		} else {
			tbuf, err := fs.CaptureField(tok)
			if err != nil {
				return fs.WrapErr(err)
			}
			err = j.Time.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 (j *Server) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	if j == nil {
		buf.WriteString("null")
		return buf.Bytes(), nil
	}
	err := j.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (j *Server) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
	if j == nil {
		buf.WriteString("null")
		return nil
	}
	var err error
	var obj []byte
	_ = obj
	_ = err
	buf.WriteString(`{"Name":`)
	fflib.WriteJsonString(buf, string(j.Name))
	buf.WriteString(`,"Services":`)
	err = buf.Encode(j.Services)
	if err != nil {
		return err
	}
	buf.WriteString(`,"LastUpdated":`)
	{
		obj, err = j.LastUpdated.MarshalJSON()
		if err != nil {
			return err
		}
		buf.Write(obj)
	}
	buf.WriteString(`,"LastChanged":`)
	{
		obj, err = j.LastChanged.MarshalJSON()
		if err != nil {
			return err
		}
		buf.Write(obj)
	}
	buf.WriteByte('}')
	return nil
}
const (
	ffjtServerbase = iota
	ffjtServernosuchkey
	ffjtServerName
	ffjtServerServices
	ffjtServerLastUpdated
	ffjtServerLastChanged
)
var ffjKeyServerName = []byte("Name")
var ffjKeyServerServices = []byte("Services")
var ffjKeyServerLastUpdated = []byte("LastUpdated")
var ffjKeyServerLastChanged = []byte("LastChanged")
func (j *Server) UnmarshalJSON(input []byte) error {
	fs := fflib.NewFFLexer(input)
	return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}
func (j *Server) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
	var err error
	currentKey := ffjtServerbase
	_ = currentKey
	tok := fflib.FFTok_init
	wantedTok := fflib.FFTok_init
mainparse:
	for {
		tok = fs.Scan()
		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:
			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 {
				currentKey = ffjtServernosuchkey
				state = fflib.FFParse_want_colon
				goto mainparse
			} else {
				switch kn[0] {
				case 'L':
					if bytes.Equal(ffjKeyServerLastUpdated, kn) {
						currentKey = ffjtServerLastUpdated
						state = fflib.FFParse_want_colon
						goto mainparse
					} else if bytes.Equal(ffjKeyServerLastChanged, kn) {
						currentKey = ffjtServerLastChanged
						state = fflib.FFParse_want_colon
						goto mainparse
					}
				case 'N':
					if bytes.Equal(ffjKeyServerName, kn) {
						currentKey = ffjtServerName
						state = fflib.FFParse_want_colon
						goto mainparse
					}
				case 'S':
					if bytes.Equal(ffjKeyServerServices, kn) {
						currentKey = ffjtServerServices
						state = fflib.FFParse_want_colon
						goto mainparse
					}
				}
				if fflib.EqualFoldRight(ffjKeyServerLastChanged, kn) {
					currentKey = ffjtServerLastChanged
					state = fflib.FFParse_want_colon
					goto mainparse
				}
				if fflib.EqualFoldRight(ffjKeyServerLastUpdated, kn) {
					currentKey = ffjtServerLastUpdated
					state = fflib.FFParse_want_colon
					goto mainparse
				}
				if fflib.EqualFoldRight(ffjKeyServerServices, kn) {
					currentKey = ffjtServerServices
					state = fflib.FFParse_want_colon
					goto mainparse
				}
				if fflib.SimpleLetterEqualFold(ffjKeyServerName, kn) {
					currentKey = ffjtServerName
					state = fflib.FFParse_want_colon
					goto mainparse
				}
				currentKey = ffjtServernosuchkey
				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 ffjtServerName:
					goto handle_Name
				case ffjtServerServices:
					goto handle_Services
				case ffjtServerLastUpdated:
					goto handle_LastUpdated
				case ffjtServerLastChanged:
					goto handle_LastChanged
				case ffjtServernosuchkey:
					err = fs.SkipField(tok)
					if err != nil {
						return fs.WrapErr(err)
					}
					state = fflib.FFParse_after_value
					goto mainparse
				}
			} else {
				goto wantedvalue
			}
		}
	}
handle_Name:
	{
		{
			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()
			j.Name = string(string(outBuf))
		}
	}
	state = fflib.FFParse_after_value
	goto mainparse
handle_Services:
	{
		{
			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 {
			j.Services = nil
		} else {
			j.Services = make(map[string]*service.Service, 0)
			wantVal := true
			for {
				var k string
				var tmpJServices *service.Service
				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 {
						return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
					}
					continue
				} else {
					wantVal = true
				}
				{
					{
						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()
						k = string(string(outBuf))
					}
				}
				tok = fs.Scan()
				if tok != fflib.FFTok_colon {
					return fs.WrapErr(fmt.Errorf("wanted colon token, but got token: %v", tok))
				}
				tok = fs.Scan()
				{
					if tok == fflib.FFTok_null {
						tmpJServices = nil
					} else {
						if tmpJServices == nil {
							tmpJServices = new(service.Service)
						}
						err = tmpJServices.UnmarshalJSONFFLexer(fs, fflib.FFParse_want_key)
						if err != nil {
							return err
						}
					}
					state = fflib.FFParse_after_value
				}
				j.Services[k] = tmpJServices
				wantVal = false
			}
		}
	}
	state = fflib.FFParse_after_value
	goto mainparse
handle_LastUpdated:
	{
		if tok == fflib.FFTok_null {
		} else {
			tbuf, err := fs.CaptureField(tok)
			if err != nil {
				return fs.WrapErr(err)
			}
			err = j.LastUpdated.UnmarshalJSON(tbuf)
			if err != nil {
				return fs.WrapErr(err)
			}
		}
		state = fflib.FFParse_after_value
	}
	state = fflib.FFParse_after_value
	goto mainparse
handle_LastChanged:
	{
		if tok == fflib.FFTok_null {
		} else {
			tbuf, err := fs.CaptureField(tok)
			if err != nil {
				return fs.WrapErr(err)
			}
			err = j.LastChanged.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 (j *ServicesState) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	if j == nil {
		buf.WriteString("null")
		return buf.Bytes(), nil
	}
	err := j.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}