// Code generated by tinyjson for marshaling/unmarshaling. DO NOT EDIT.

package state

import (
	tinyjson "github.com/CosmWasm/tinyjson"
	jlexer "github.com/CosmWasm/tinyjson/jlexer"
	jwriter "github.com/CosmWasm/tinyjson/jwriter"
)

// suppress unused package warning
var (
	_ *jlexer.Lexer
	_ *jwriter.Writer
	_ tinyjson.Marshaler
)

func tinyjsonEa1f3371DecodeGithubComArchwayNetworkVoterSrcState(in *jlexer.Lexer, out *Voting) {
	isTopLevel := in.IsStart()
	if in.IsNull() {
		if isTopLevel {
			in.Consumed()
		}
		in.Skip()
		return
	}
	in.Delim('{')
	for !in.IsDelim('}') {
		key := in.UnsafeFieldName(false)
		in.WantColon()
		if in.IsNull() {
			in.Skip()
			in.WantComma()
			continue
		}
		switch key {
		case "id":
			out.ID = uint64(in.Uint64())
		case "name":
			out.Name = string(in.String())
		case "creator_addr":
			out.CreatorAddr = string(in.String())
		case "start_time":
			out.StartTime = uint64(in.Uint64())
		case "end_time":
			out.EndTime = uint64(in.Uint64())
		case "tallies":
			if in.IsNull() {
				in.Skip()
				out.Tallies = nil
			} else {
				in.Delim('[')
				if out.Tallies == nil {
					if !in.IsDelim(']') {
						out.Tallies = make([]Tally, 0, 1)
					} else {
						out.Tallies = []Tally{}
					}
				} else {
					out.Tallies = (out.Tallies)[:0]
				}
				for !in.IsDelim(']') {
					var v1 Tally
					(v1).UnmarshalTinyJSON(in)
					out.Tallies = append(out.Tallies, v1)
					in.WantComma()
				}
				in.Delim(']')
			}
		default:
			in.SkipRecursive()
		}
		in.WantComma()
	}
	in.Delim('}')
	if isTopLevel {
		in.Consumed()
	}
}
func tinyjsonEa1f3371EncodeGithubComArchwayNetworkVoterSrcState(out *jwriter.Writer, in Voting) {
	out.RawByte('{')
	first := true
	_ = first
	{
		const prefix string = ",\"id\":"
		out.RawString(prefix[1:])
		out.Uint64(uint64(in.ID))
	}
	{
		const prefix string = ",\"name\":"
		out.RawString(prefix)
		out.String(string(in.Name))
	}
	{
		const prefix string = ",\"creator_addr\":"
		out.RawString(prefix)
		out.String(string(in.CreatorAddr))
	}
	{
		const prefix string = ",\"start_time\":"
		out.RawString(prefix)
		out.Uint64(uint64(in.StartTime))
	}
	{
		const prefix string = ",\"end_time\":"
		out.RawString(prefix)
		out.Uint64(uint64(in.EndTime))
	}
	{
		const prefix string = ",\"tallies\":"
		out.RawString(prefix)
		if in.Tallies == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
			out.RawString("null")
		} else {
			out.RawByte('[')
			for v2, v3 := range in.Tallies {
				if v2 > 0 {
					out.RawByte(',')
				}
				(v3).MarshalTinyJSON(out)
			}
			out.RawByte(']')
		}
	}
	out.RawByte('}')
}

// MarshalJSON supports json.Marshaler interface
func (v Voting) MarshalJSON() ([]byte, error) {
	w := jwriter.Writer{}
	tinyjsonEa1f3371EncodeGithubComArchwayNetworkVoterSrcState(&w, v)
	return w.Buffer.BuildBytes(), w.Error
}

// MarshalTinyJSON supports tinyjson.Marshaler interface
func (v Voting) MarshalTinyJSON(w *jwriter.Writer) {
	tinyjsonEa1f3371EncodeGithubComArchwayNetworkVoterSrcState(w, v)
}

// UnmarshalJSON supports json.Unmarshaler interface
func (v *Voting) UnmarshalJSON(data []byte) error {
	r := jlexer.Lexer{Data: data}
	tinyjsonEa1f3371DecodeGithubComArchwayNetworkVoterSrcState(&r, v)
	return r.Error()
}

// UnmarshalTinyJSON supports tinyjson.Unmarshaler interface
func (v *Voting) UnmarshalTinyJSON(l *jlexer.Lexer) {
	tinyjsonEa1f3371DecodeGithubComArchwayNetworkVoterSrcState(l, v)
}
func tinyjsonEa1f3371DecodeGithubComArchwayNetworkVoterSrcState1(in *jlexer.Lexer, out *Tally) {
	isTopLevel := in.IsStart()
	if in.IsNull() {
		if isTopLevel {
			in.Consumed()
		}
		in.Skip()
		return
	}
	in.Delim('{')
	for !in.IsDelim('}') {
		key := in.UnsafeFieldName(false)
		in.WantColon()
		if in.IsNull() {
			in.Skip()
			in.WantComma()
			continue
		}
		switch key {
		case "option":
			out.Option = string(in.String())
		case "yes_addrs":
			if in.IsNull() {
				in.Skip()
				out.YesAddrs = nil
			} else {
				in.Delim('[')
				if out.YesAddrs == nil {
					if !in.IsDelim(']') {
						out.YesAddrs = make([]string, 0, 4)
					} else {
						out.YesAddrs = []string{}
					}
				} else {
					out.YesAddrs = (out.YesAddrs)[:0]
				}
				for !in.IsDelim(']') {
					var v4 string
					v4 = string(in.String())
					out.YesAddrs = append(out.YesAddrs, v4)
					in.WantComma()
				}
				in.Delim(']')
			}
		case "no_addrs":
			if in.IsNull() {
				in.Skip()
				out.NoAddrs = nil
			} else {
				in.Delim('[')
				if out.NoAddrs == nil {
					if !in.IsDelim(']') {
						out.NoAddrs = make([]string, 0, 4)
					} else {
						out.NoAddrs = []string{}
					}
				} else {
					out.NoAddrs = (out.NoAddrs)[:0]
				}
				for !in.IsDelim(']') {
					var v5 string
					v5 = string(in.String())
					out.NoAddrs = append(out.NoAddrs, v5)
					in.WantComma()
				}
				in.Delim(']')
			}
		default:
			in.SkipRecursive()
		}
		in.WantComma()
	}
	in.Delim('}')
	if isTopLevel {
		in.Consumed()
	}
}
func tinyjsonEa1f3371EncodeGithubComArchwayNetworkVoterSrcState1(out *jwriter.Writer, in Tally) {
	out.RawByte('{')
	first := true
	_ = first
	{
		const prefix string = ",\"option\":"
		out.RawString(prefix[1:])
		out.String(string(in.Option))
	}
	{
		const prefix string = ",\"yes_addrs\":"
		out.RawString(prefix)
		if in.YesAddrs == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
			out.RawString("null")
		} else {
			out.RawByte('[')
			for v6, v7 := range in.YesAddrs {
				if v6 > 0 {
					out.RawByte(',')
				}
				out.String(string(v7))
			}
			out.RawByte(']')
		}
	}
	{
		const prefix string = ",\"no_addrs\":"
		out.RawString(prefix)
		if in.NoAddrs == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
			out.RawString("null")
		} else {
			out.RawByte('[')
			for v8, v9 := range in.NoAddrs {
				if v8 > 0 {
					out.RawByte(',')
				}
				out.String(string(v9))
			}
			out.RawByte(']')
		}
	}
	out.RawByte('}')
}

// MarshalJSON supports json.Marshaler interface
func (v Tally) MarshalJSON() ([]byte, error) {
	w := jwriter.Writer{}
	tinyjsonEa1f3371EncodeGithubComArchwayNetworkVoterSrcState1(&w, v)
	return w.Buffer.BuildBytes(), w.Error
}

// MarshalTinyJSON supports tinyjson.Marshaler interface
func (v Tally) MarshalTinyJSON(w *jwriter.Writer) {
	tinyjsonEa1f3371EncodeGithubComArchwayNetworkVoterSrcState1(w, v)
}

// UnmarshalJSON supports json.Unmarshaler interface
func (v *Tally) UnmarshalJSON(data []byte) error {
	r := jlexer.Lexer{Data: data}
	tinyjsonEa1f3371DecodeGithubComArchwayNetworkVoterSrcState1(&r, v)
	return r.Error()
}

// UnmarshalTinyJSON supports tinyjson.Unmarshaler interface
func (v *Tally) UnmarshalTinyJSON(l *jlexer.Lexer) {
	tinyjsonEa1f3371DecodeGithubComArchwayNetworkVoterSrcState1(l, v)
}
