github.com/nibnait/go-learn@v0.0.0-20220227013611-dfa47ea6d2da/src/test/chapter/ch8/01_json/struct_def_easyjson.go (about)

     1  // Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT.
     2  
     3  package json
     4  
     5  import (
     6  	json "encoding/json"
     7  	easyjson "github.com/mailru/easyjson"
     8  	jlexer "github.com/mailru/easyjson/jlexer"
     9  	jwriter "github.com/mailru/easyjson/jwriter"
    10  )
    11  
    12  // suppress unused package warning
    13  var (
    14  	_ *json.RawMessage
    15  	_ *jlexer.Lexer
    16  	_ *jwriter.Writer
    17  	_ easyjson.Marshaler
    18  )
    19  
    20  func easyjson7c82d03DecodeGoLearnSrcTestCh8Json(in *jlexer.Lexer, out *JobInfo) {
    21  	isTopLevel := in.IsStart()
    22  	if in.IsNull() {
    23  		if isTopLevel {
    24  			in.Consumed()
    25  		}
    26  		in.Skip()
    27  		return
    28  	}
    29  	in.Delim('{')
    30  	for !in.IsDelim('}') {
    31  		key := in.UnsafeFieldName(false)
    32  		in.WantColon()
    33  		if in.IsNull() {
    34  			in.Skip()
    35  			in.WantComma()
    36  			continue
    37  		}
    38  		switch key {
    39  		case "skills":
    40  			if in.IsNull() {
    41  				in.Skip()
    42  				out.Skills = nil
    43  			} else {
    44  				in.Delim('[')
    45  				if out.Skills == nil {
    46  					if !in.IsDelim(']') {
    47  						out.Skills = make([]string, 0, 4)
    48  					} else {
    49  						out.Skills = []string{}
    50  					}
    51  				} else {
    52  					out.Skills = (out.Skills)[:0]
    53  				}
    54  				for !in.IsDelim(']') {
    55  					var v1 string
    56  					v1 = string(in.String())
    57  					out.Skills = append(out.Skills, v1)
    58  					in.WantComma()
    59  				}
    60  				in.Delim(']')
    61  			}
    62  		default:
    63  			in.SkipRecursive()
    64  		}
    65  		in.WantComma()
    66  	}
    67  	in.Delim('}')
    68  	if isTopLevel {
    69  		in.Consumed()
    70  	}
    71  }
    72  func easyjson7c82d03EncodeGoLearnSrcTestCh8Json(out *jwriter.Writer, in JobInfo) {
    73  	out.RawByte('{')
    74  	first := true
    75  	_ = first
    76  	{
    77  		const prefix string = ",\"skills\":"
    78  		out.RawString(prefix[1:])
    79  		if in.Skills == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
    80  			out.RawString("null")
    81  		} else {
    82  			out.RawByte('[')
    83  			for v2, v3 := range in.Skills {
    84  				if v2 > 0 {
    85  					out.RawByte(',')
    86  				}
    87  				out.String(string(v3))
    88  			}
    89  			out.RawByte(']')
    90  		}
    91  	}
    92  	out.RawByte('}')
    93  }
    94  
    95  // MarshalJSON supports 01_json.Marshaler interface
    96  func (v JobInfo) MarshalJSON() ([]byte, error) {
    97  	w := jwriter.Writer{}
    98  	easyjson7c82d03EncodeGoLearnSrcTestCh8Json(&w, v)
    99  	return w.Buffer.BuildBytes(), w.Error
   100  }
   101  
   102  // MarshalEasyJSON supports easyjson.Marshaler interface
   103  func (v JobInfo) MarshalEasyJSON(w *jwriter.Writer) {
   104  	easyjson7c82d03EncodeGoLearnSrcTestCh8Json(w, v)
   105  }
   106  
   107  // UnmarshalJSON supports 01_json.Unmarshaler interface
   108  func (v *JobInfo) UnmarshalJSON(data []byte) error {
   109  	r := jlexer.Lexer{Data: data}
   110  	easyjson7c82d03DecodeGoLearnSrcTestCh8Json(&r, v)
   111  	return r.Error()
   112  }
   113  
   114  // UnmarshalEasyJSON supports easyjson.Unmarshaler interface
   115  func (v *JobInfo) UnmarshalEasyJSON(l *jlexer.Lexer) {
   116  	easyjson7c82d03DecodeGoLearnSrcTestCh8Json(l, v)
   117  }
   118  func easyjson7c82d03DecodeGoLearnSrcTestCh8Json1(in *jlexer.Lexer, out *Employee) {
   119  	isTopLevel := in.IsStart()
   120  	if in.IsNull() {
   121  		if isTopLevel {
   122  			in.Consumed()
   123  		}
   124  		in.Skip()
   125  		return
   126  	}
   127  	in.Delim('{')
   128  	for !in.IsDelim('}') {
   129  		key := in.UnsafeFieldName(false)
   130  		in.WantColon()
   131  		if in.IsNull() {
   132  			in.Skip()
   133  			in.WantComma()
   134  			continue
   135  		}
   136  		switch key {
   137  		case "basic_info":
   138  			(out.BasicInfo).UnmarshalEasyJSON(in)
   139  		case "job_info":
   140  			(out.JobInfo).UnmarshalEasyJSON(in)
   141  		default:
   142  			in.SkipRecursive()
   143  		}
   144  		in.WantComma()
   145  	}
   146  	in.Delim('}')
   147  	if isTopLevel {
   148  		in.Consumed()
   149  	}
   150  }
   151  func easyjson7c82d03EncodeGoLearnSrcTestCh8Json1(out *jwriter.Writer, in Employee) {
   152  	out.RawByte('{')
   153  	first := true
   154  	_ = first
   155  	{
   156  		const prefix string = ",\"basic_info\":"
   157  		out.RawString(prefix[1:])
   158  		(in.BasicInfo).MarshalEasyJSON(out)
   159  	}
   160  	{
   161  		const prefix string = ",\"job_info\":"
   162  		out.RawString(prefix)
   163  		(in.JobInfo).MarshalEasyJSON(out)
   164  	}
   165  	out.RawByte('}')
   166  }
   167  
   168  // MarshalJSON supports 01_json.Marshaler interface
   169  func (v Employee) MarshalJSON() ([]byte, error) {
   170  	w := jwriter.Writer{}
   171  	easyjson7c82d03EncodeGoLearnSrcTestCh8Json1(&w, v)
   172  	return w.Buffer.BuildBytes(), w.Error
   173  }
   174  
   175  // MarshalEasyJSON supports easyjson.Marshaler interface
   176  func (v Employee) MarshalEasyJSON(w *jwriter.Writer) {
   177  	easyjson7c82d03EncodeGoLearnSrcTestCh8Json1(w, v)
   178  }
   179  
   180  // UnmarshalJSON supports 01_json.Unmarshaler interface
   181  func (v *Employee) UnmarshalJSON(data []byte) error {
   182  	r := jlexer.Lexer{Data: data}
   183  	easyjson7c82d03DecodeGoLearnSrcTestCh8Json1(&r, v)
   184  	return r.Error()
   185  }
   186  
   187  // UnmarshalEasyJSON supports easyjson.Unmarshaler interface
   188  func (v *Employee) UnmarshalEasyJSON(l *jlexer.Lexer) {
   189  	easyjson7c82d03DecodeGoLearnSrcTestCh8Json1(l, v)
   190  }
   191  func easyjson7c82d03DecodeGoLearnSrcTestCh8Json2(in *jlexer.Lexer, out *BasicInfo) {
   192  	isTopLevel := in.IsStart()
   193  	if in.IsNull() {
   194  		if isTopLevel {
   195  			in.Consumed()
   196  		}
   197  		in.Skip()
   198  		return
   199  	}
   200  	in.Delim('{')
   201  	for !in.IsDelim('}') {
   202  		key := in.UnsafeFieldName(false)
   203  		in.WantColon()
   204  		if in.IsNull() {
   205  			in.Skip()
   206  			in.WantComma()
   207  			continue
   208  		}
   209  		switch key {
   210  		case "name":
   211  			out.Name = string(in.String())
   212  		case "age":
   213  			out.Age = int(in.Int())
   214  		default:
   215  			in.SkipRecursive()
   216  		}
   217  		in.WantComma()
   218  	}
   219  	in.Delim('}')
   220  	if isTopLevel {
   221  		in.Consumed()
   222  	}
   223  }
   224  func easyjson7c82d03EncodeGoLearnSrcTestCh8Json2(out *jwriter.Writer, in BasicInfo) {
   225  	out.RawByte('{')
   226  	first := true
   227  	_ = first
   228  	{
   229  		const prefix string = ",\"name\":"
   230  		out.RawString(prefix[1:])
   231  		out.String(string(in.Name))
   232  	}
   233  	{
   234  		const prefix string = ",\"age\":"
   235  		out.RawString(prefix)
   236  		out.Int(int(in.Age))
   237  	}
   238  	out.RawByte('}')
   239  }
   240  
   241  // MarshalJSON supports 01_json.Marshaler interface
   242  func (v BasicInfo) MarshalJSON() ([]byte, error) {
   243  	w := jwriter.Writer{}
   244  	easyjson7c82d03EncodeGoLearnSrcTestCh8Json2(&w, v)
   245  	return w.Buffer.BuildBytes(), w.Error
   246  }
   247  
   248  // MarshalEasyJSON supports easyjson.Marshaler interface
   249  func (v BasicInfo) MarshalEasyJSON(w *jwriter.Writer) {
   250  	easyjson7c82d03EncodeGoLearnSrcTestCh8Json2(w, v)
   251  }
   252  
   253  // UnmarshalJSON supports 01_json.Unmarshaler interface
   254  func (v *BasicInfo) UnmarshalJSON(data []byte) error {
   255  	r := jlexer.Lexer{Data: data}
   256  	easyjson7c82d03DecodeGoLearnSrcTestCh8Json2(&r, v)
   257  	return r.Error()
   258  }
   259  
   260  // UnmarshalEasyJSON supports easyjson.Unmarshaler interface
   261  func (v *BasicInfo) UnmarshalEasyJSON(l *jlexer.Lexer) {
   262  	easyjson7c82d03DecodeGoLearnSrcTestCh8Json2(l, v)
   263  }