github.com/nibnait/go-learn@v0.0.0-20220227013611-dfa47ea6d2da/src/test/chapter/ch9/01_optimize_eg/structs_easyjson.go (about) 1 // Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. 2 3 package profiling 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 easyjson6a975c40DecodeGoLearnSrcTestCh9(in *jlexer.Lexer, out *Response) { 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 "transaction_id": 40 out.TransactionID = string(in.String()) 41 case "exp": 42 out.Expression = string(in.String()) 43 default: 44 in.SkipRecursive() 45 } 46 in.WantComma() 47 } 48 in.Delim('}') 49 if isTopLevel { 50 in.Consumed() 51 } 52 } 53 func easyjson6a975c40EncodeGoLearnSrcTestCh9(out *jwriter.Writer, in Response) { 54 out.RawByte('{') 55 first := true 56 _ = first 57 { 58 const prefix string = ",\"transaction_id\":" 59 out.RawString(prefix[1:]) 60 out.String(string(in.TransactionID)) 61 } 62 { 63 const prefix string = ",\"exp\":" 64 out.RawString(prefix) 65 out.String(string(in.Expression)) 66 } 67 out.RawByte('}') 68 } 69 70 // MarshalJSON supports json.Marshaler interface 71 func (v Response) MarshalJSON() ([]byte, error) { 72 w := jwriter.Writer{} 73 easyjson6a975c40EncodeGoLearnSrcTestCh9(&w, v) 74 return w.Buffer.BuildBytes(), w.Error 75 } 76 77 // MarshalEasyJSON supports easyjson.Marshaler interface 78 func (v Response) MarshalEasyJSON(w *jwriter.Writer) { 79 easyjson6a975c40EncodeGoLearnSrcTestCh9(w, v) 80 } 81 82 // UnmarshalJSON supports json.Unmarshaler interface 83 func (v *Response) UnmarshalJSON(data []byte) error { 84 r := jlexer.Lexer{Data: data} 85 easyjson6a975c40DecodeGoLearnSrcTestCh9(&r, v) 86 return r.Error() 87 } 88 89 // UnmarshalEasyJSON supports easyjson.Unmarshaler interface 90 func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer) { 91 easyjson6a975c40DecodeGoLearnSrcTestCh9(l, v) 92 } 93 func easyjson6a975c40DecodeGoLearnSrcTestCh91(in *jlexer.Lexer, out *Request) { 94 isTopLevel := in.IsStart() 95 if in.IsNull() { 96 if isTopLevel { 97 in.Consumed() 98 } 99 in.Skip() 100 return 101 } 102 in.Delim('{') 103 for !in.IsDelim('}') { 104 key := in.UnsafeFieldName(false) 105 in.WantColon() 106 if in.IsNull() { 107 in.Skip() 108 in.WantComma() 109 continue 110 } 111 switch key { 112 case "transaction_id": 113 out.TransactionID = string(in.String()) 114 case "payload": 115 if in.IsNull() { 116 in.Skip() 117 out.PayLoad = nil 118 } else { 119 in.Delim('[') 120 if out.PayLoad == nil { 121 if !in.IsDelim(']') { 122 out.PayLoad = make([]int, 0, 8) 123 } else { 124 out.PayLoad = []int{} 125 } 126 } else { 127 out.PayLoad = (out.PayLoad)[:0] 128 } 129 for !in.IsDelim(']') { 130 var v1 int 131 v1 = int(in.Int()) 132 out.PayLoad = append(out.PayLoad, v1) 133 in.WantComma() 134 } 135 in.Delim(']') 136 } 137 default: 138 in.SkipRecursive() 139 } 140 in.WantComma() 141 } 142 in.Delim('}') 143 if isTopLevel { 144 in.Consumed() 145 } 146 } 147 func easyjson6a975c40EncodeGoLearnSrcTestCh91(out *jwriter.Writer, in Request) { 148 out.RawByte('{') 149 first := true 150 _ = first 151 { 152 const prefix string = ",\"transaction_id\":" 153 out.RawString(prefix[1:]) 154 out.String(string(in.TransactionID)) 155 } 156 { 157 const prefix string = ",\"payload\":" 158 out.RawString(prefix) 159 if in.PayLoad == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { 160 out.RawString("null") 161 } else { 162 out.RawByte('[') 163 for v2, v3 := range in.PayLoad { 164 if v2 > 0 { 165 out.RawByte(',') 166 } 167 out.Int(int(v3)) 168 } 169 out.RawByte(']') 170 } 171 } 172 out.RawByte('}') 173 } 174 175 // MarshalJSON supports json.Marshaler interface 176 func (v Request) MarshalJSON() ([]byte, error) { 177 w := jwriter.Writer{} 178 easyjson6a975c40EncodeGoLearnSrcTestCh91(&w, v) 179 return w.Buffer.BuildBytes(), w.Error 180 } 181 182 // MarshalEasyJSON supports easyjson.Marshaler interface 183 func (v Request) MarshalEasyJSON(w *jwriter.Writer) { 184 easyjson6a975c40EncodeGoLearnSrcTestCh91(w, v) 185 } 186 187 // UnmarshalJSON supports json.Unmarshaler interface 188 func (v *Request) UnmarshalJSON(data []byte) error { 189 r := jlexer.Lexer{Data: data} 190 easyjson6a975c40DecodeGoLearnSrcTestCh91(&r, v) 191 return r.Error() 192 } 193 194 // UnmarshalEasyJSON supports easyjson.Unmarshaler interface 195 func (v *Request) UnmarshalEasyJSON(l *jlexer.Lexer) { 196 easyjson6a975c40DecodeGoLearnSrcTestCh91(l, v) 197 }