gen-dec-map.go.tmpl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. {{var "v"}} := *{{ .Varname }}
  2. {{var "l"}} := z.DecReadMapStart()
  3. {{var "bh"}} := z.DecBasicHandle()
  4. if {{var "v"}} == nil {
  5. {{var "rl"}} := z.DecInferLen({{var "l"}}, {{var "bh"}}.MaxInitLen, {{ .Size }})
  6. {{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}, {{var "rl"}})
  7. *{{ .Varname }} = {{var "v"}}
  8. }
  9. var {{var "mk"}} {{ .KTyp }}
  10. var {{var "mv"}} {{ .Typ }}
  11. var {{var "mg"}}, {{var "mdn"}} {{if decElemKindPtr}}, {{var "ms"}}, {{var "mok"}}{{end}} bool
  12. if {{var "bh"}}.MapValueReset {
  13. {{if decElemKindPtr}}{{var "mg"}} = true
  14. {{else if decElemKindIntf}}if !{{var "bh"}}.InterfaceReset { {{var "mg"}} = true }
  15. {{else if not decElemKindImmutable}}{{var "mg"}} = true
  16. {{end}} }
  17. if {{var "l"}} != 0 {
  18. {{var "hl"}} := {{var "l"}} > 0
  19. for {{var "j"}} := 0; ({{var "hl"}} && {{var "j"}} < {{var "l"}}) || !({{var "hl"}} || r.CheckBreak()); {{var "j"}}++ {
  20. z.DecReadMapElemKey() {{/* z.DecSendContainerState(codecSelfer_containerMapKey{{ .Sfx }}) */}}
  21. {{ $x := printf "%vmk%v" .TempVar .Rand }}{{ decLineVarK $x -}}
  22. {{ if eq .KTyp "interface{}" }}{{/* // special case if a byte array. */ -}}
  23. if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} {
  24. {{var "mk"}} = string({{var "bv"}})
  25. }
  26. {{ end -}}
  27. {{if decElemKindPtr -}}
  28. {{var "ms"}} = true
  29. {{end -}}
  30. if {{var "mg"}} {
  31. {{if decElemKindPtr -}}
  32. {{var "mv"}}, {{var "mok"}} = {{var "v"}}[{{var "mk"}}]
  33. if {{var "mok"}} {
  34. {{var "ms"}} = false
  35. }
  36. {{else -}}
  37. {{var "mv"}} = {{var "v"}}[{{var "mk"}}]
  38. {{end -}}
  39. } {{if not decElemKindImmutable}}else { {{var "mv"}} = {{decElemZero}} }{{end}}
  40. z.DecReadMapElemValue() {{/* z.DecSendContainerState(codecSelfer_containerMapValue{{ .Sfx }}) */}}
  41. {{var "mdn"}} = false
  42. {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ $y := printf "%vmdn%v" .TempVar .Rand }}{{ decLineVar $x $y -}}
  43. if {{var "mdn"}} {
  44. if {{ var "bh" }}.DeleteOnNilMapValue { delete({{var "v"}}, {{var "mk"}}) } else { {{var "v"}}[{{var "mk"}}] = {{decElemZero}} }
  45. } else if {{if decElemKindPtr}} {{var "ms"}} && {{end}} {{var "v"}} != nil {
  46. {{var "v"}}[{{var "mk"}}] = {{var "mv"}}
  47. }
  48. }
  49. } // else len==0: TODO: Should we clear map entries?
  50. z.DecReadMapEnd() {{/* z.DecSendContainerState(codecSelfer_containerMapEnd{{ .Sfx }}) */}}