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

Method mapstruct

gen/unmarshal.go:293–387  ·  view source on GitHub ↗
(s *Struct)

Source from the content-addressed store, hash-verified

291}
292
293func (u *unmarshalGen) mapstruct(s *Struct) {
294 u.needsField()
295 sz := randIdent()
296 u.p.declare(sz, u32)
297 u.assignMap(sz, mapHeader, 0)
298
299 oeCount := s.CountFieldTagPart("omitempty") + s.CountFieldTagPart("omitzero")
300 if !u.ctx.clearOmitted {
301 oeCount = 0
302 }
303 bm := bmask{
304 bitlen: oeCount,
305 varname: sz + "Mask",
306 }
307 if oeCount > 0 {
308 // Declare mask
309 u.p.printf("\n%s", bm.typeDecl())
310 u.p.printf("\n_ = %s", bm.varname)
311 }
312 // Index to field idx of each emitted
313 oeEmittedIdx := []int{}
314
315 u.p.printf("\nfor %s > 0 {", sz)
316 u.p.printf("\n%s--; field, bts, err = msgp.ReadMapKeyZC(bts)", sz)
317 u.p.wrapErrCheck(u.ctx.ArgsStr())
318 u.p.print("\nswitch msgp.UnsafeString(field) {")
319 for i := range s.Fields {
320 if !u.p.ok() {
321 return
322 }
323 u.p.printf("\ncase %q:", s.Fields[i].FieldTag)
324 u.ctx.PushString(s.Fields[i].FieldName)
325
326 fieldElem := s.Fields[i].FieldElem
327 anField := s.Fields[i].HasTagPart("allownil") && fieldElem.AllowNil()
328
329 // Set field-specific limits in context based on struct field's FieldLimit
330 if s.Fields[i].FieldLimit > 0 {
331 // Apply same limit to both arrays and maps for this field
332 u.ctx.SetFieldLimits(s.Fields[i].FieldLimit, s.Fields[i].FieldLimit)
333 } else {
334 u.ctx.ClearFieldLimits()
335 }
336
337 if anField {
338 u.p.printf("\nif msgp.IsNil(bts) {\nbts = bts[1:]\n%s = nil\n} else {", fieldElem.Varname())
339 }
340 SetIsAllowNil(fieldElem, anField)
341 if s.Fields[i].HasTagPart("zerocopy") {
342 setRecursiveZC(fieldElem, true)
343 }
344 setTypeParams(fieldElem, s.typeParams)
345
346 next(u, fieldElem)
347
348 // Clear field limits after processing
349 u.ctx.ClearFieldLimits()
350

Callers 1

gStructMethod · 0.95

Calls 15

needsFieldMethod · 0.95
assignMapMethod · 0.95
typeDeclMethod · 0.95
setStmtMethod · 0.95
notAllSetMethod · 0.95
readExprMethod · 0.95
randIdentFunction · 0.85
SetIsAllowNilFunction · 0.85
setRecursiveZCFunction · 0.85
setTypeParamsFunction · 0.85
nextFunction · 0.85
declareMethod · 0.80

Tested by

no test coverage detected