github.com/ugorji/go/codec@v1.2.13-0.20240307214044-07c54c229a5a/gen-dec-map.go.tmpl (about)

     1  {{var "v"}} := *{{ .Varname }}
     2  {{var "l"}} := z.DecReadMapStart()
     3  if {{var "l"}} == codecSelferDecContainerLenNil{{xs}} {
     4  	*{{ .Varname }} = nil
     5  } else {
     6  if {{var "v"}} == nil {
     7  	{{var "rl"}} := z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
     8  	{{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}, {{var "rl"}})
     9  	*{{ .Varname }} = {{var "v"}}
    10  }
    11  {{ $mk := var "mk" -}}
    12  var {{ $mk }} {{ .KTyp }}
    13  var {{var "mv"}} {{ .Typ }}
    14  var {{var "mg"}}, {{var "mdn"}} {{if decElemKindPtr}}, {{var "ms"}}, {{var "mok"}}{{end}} bool
    15  if z.DecBasicHandle().MapValueReset {
    16  	{{if decElemKindPtr}}{{var "mg"}} = true
    17  	{{else if decElemKindIntf}}if !z.DecBasicHandle().InterfaceReset { {{var "mg"}} = true }
    18  	{{else if not decElemKindImmutable}}{{var "mg"}} = true
    19  	{{end}} }
    20  if {{var "l"}} != 0 {
    21  	{{var "hl"}} := {{var "l"}} > 0 
    22  	for {{var "j"}} := 0; z.DecContainerNext({{var "j"}}, {{var "l"}}, {{var "hl"}}); {{var "j"}}++ {
    23  	z.DecReadMapElemKey()
    24  	{{ if eq .KTyp "string" -}}
    25  		{{ decLineVarK $mk -}}{{- /* decLineVarKStrZC $mk */ -}}
    26  	{{ else -}}
    27  		{{ decLineVarK $mk -}}
    28  	{{ end -}}
    29  	{{ if eq .KTyp "interface{}" }}{{/* // special case if a byte array. */ -}}
    30      if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} {
    31  		{{var "mk"}} = z.DecStringZC({{var "bv"}})
    32  	}
    33      {{ end -}}
    34      {{if decElemKindPtr -}}
    35  	{{var "ms"}} = true
    36      {{end -}}
    37  	if {{var "mg"}} {
    38  		{{if decElemKindPtr -}}
    39          {{var "mv"}}, {{var "mok"}} = {{var "v"}}[{{ $mk }}]
    40  		if {{var "mok"}} {
    41  			{{var "ms"}} = false
    42  		}
    43          {{else -}}
    44          {{var "mv"}} = {{var "v"}}[{{ $mk }}]
    45          {{end -}}
    46  	} {{if not decElemKindImmutable}}else { {{var "mv"}} = {{decElemZero}} }{{end}}
    47  	z.DecReadMapElemValue()
    48  	{{var "mdn"}} = false
    49  	{{ $x := printf "%vmv%v" .TempVar .Rand }}{{ $y := printf "%vmdn%v" .TempVar .Rand }}{{ decLineVar $x $y -}}
    50  	if {{var "mdn"}} {
    51  		{{var "v"}}[{{ $mk }}] = {{decElemZero}}
    52  	} else {{if decElemKindPtr}} if {{var "ms"}} {{end}} {
    53  		{{var "v"}}[{{ $mk }}] = {{var "mv"}}
    54  	}
    55  }
    56  } // else len==0: leave as-is (do not clear map entries)
    57  z.DecReadMapEnd()
    58  }