MCPcopy
hub / github.com/tinylib/msgp / structAsTuple

Method structAsTuple

gen/decode.go:184–234  ·  view source on GitHub ↗
(s *Struct)

Source from the content-addressed store, hash-verified

182}
183
184func (d *decodeGen) structAsTuple(s *Struct) {
185 sz := randIdent()
186 d.p.declare(sz, u32)
187 d.assignArray(sz, arrayHeader, 0)
188 if s.AsVarTuple {
189 d.p.printf("\nfor %[1]s > 0 {", sz) // start the block
190 } else {
191 d.p.arrayCheck(strconv.Itoa(len(s.Fields)), sz)
192 }
193 for i := range s.Fields {
194 if !d.p.ok() {
195 return
196 }
197 fieldElem := s.Fields[i].FieldElem
198 anField := s.Fields[i].HasTagPart("allownil") && fieldElem.AllowNil()
199
200 // Set field-specific limits in context based on struct field's FieldLimit
201 if s.Fields[i].FieldLimit > 0 {
202 // Apply same limit to both arrays and maps for this field
203 d.ctx.SetFieldLimits(s.Fields[i].FieldLimit, s.Fields[i].FieldLimit)
204 } else {
205 d.ctx.ClearFieldLimits()
206 }
207
208 if anField {
209 d.p.print("\nif dc.IsNil() {")
210 d.p.print("\nerr = dc.ReadNil()")
211 d.p.wrapErrCheck(d.ctx.ArgsStr())
212 d.p.printf("\n%s = nil\n} else {", s.Fields[i].FieldElem.Varname())
213 }
214 SetIsAllowNil(fieldElem, anField)
215 d.ctx.PushString(s.Fields[i].FieldName)
216 setTypeParams(fieldElem, s.typeParams)
217 next(d, fieldElem)
218
219 // Clear field limits after processing
220 d.ctx.ClearFieldLimits()
221
222 d.ctx.Pop()
223 if anField {
224 d.p.printf("\n}") // close if statement
225 }
226 if s.AsVarTuple {
227 d.p.printf("\nif %[1]s--; %[1]s == 0 { break }", sz) // exit from the block
228 }
229 }
230 if s.AsVarTuple {
231 d.p.printf("\nfor ; %[1]s > 0; %[1]s-- {\nif err = dc.Skip(); err != nil {\nerr = msgp.WrapError(err)\nreturn\n}\n}", sz)
232 d.p.printf("\n}") // end the block
233 }
234}
235
236func (d *decodeGen) structAsMap(s *Struct) {
237 d.needsField()

Callers 1

gStructMethod · 0.95

Calls 15

assignArrayMethod · 0.95
randIdentFunction · 0.85
SetIsAllowNilFunction · 0.85
setTypeParamsFunction · 0.85
nextFunction · 0.85
declareMethod · 0.80
printfMethod · 0.80
arrayCheckMethod · 0.80
okMethod · 0.80
HasTagPartMethod · 0.80
SetFieldLimitsMethod · 0.80
ClearFieldLimitsMethod · 0.80

Tested by

no test coverage detected