gen-dec-map.go.tmpl 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. {{var "v"}} := *{{ .Varname }}
  2. {{var "l"}} := r.ReadMapStart()
  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"}} {{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. for {{var "j"}} := 0; {{var "j"}} < {{var "l"}}; {{var "j"}}++ {
  19. z.DecSendContainerState(codecSelfer_containerMapKey{{ .Sfx }})
  20. {{ $x := printf "%vmk%v" .TempVar .Rand }}{{ decLineVarK $x }}
  21. {{ if eq .KTyp "interface{}" }}{{/* // special case if a byte array. */}}if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} {
  22. {{var "mk"}} = string({{var "bv"}})
  23. }{{ end }}{{if decElemKindPtr}}
  24. {{var "ms"}} = true{{end}}
  25. if {{var "mg"}} {
  26. {{if decElemKindPtr}}{{var "mv"}}, {{var "mok"}} = {{var "v"}}[{{var "mk"}}]
  27. if {{var "mok"}} {
  28. {{var "ms"}} = false
  29. } {{else}}{{var "mv"}} = {{var "v"}}[{{var "mk"}}] {{end}}
  30. } {{if not decElemKindImmutable}}else { {{var "mv"}} = {{decElemZero}} }{{end}}
  31. z.DecSendContainerState(codecSelfer_containerMapValue{{ .Sfx }})
  32. {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ decLineVar $x }}
  33. if {{if decElemKindPtr}} {{var "ms"}} && {{end}} {{var "v"}} != nil {
  34. {{var "v"}}[{{var "mk"}}] = {{var "mv"}}
  35. }
  36. }
  37. } else if {{var "l"}} < 0 {
  38. for {{var "j"}} := 0; !r.CheckBreak(); {{var "j"}}++ {
  39. z.DecSendContainerState(codecSelfer_containerMapKey{{ .Sfx }})
  40. {{ $x := printf "%vmk%v" .TempVar .Rand }}{{ decLineVarK $x }}
  41. {{ if eq .KTyp "interface{}" }}{{/* // special case if a byte array. */}}if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} {
  42. {{var "mk"}} = string({{var "bv"}})
  43. }{{ end }}{{if decElemKindPtr}}
  44. {{var "ms"}} = true {{ end }}
  45. if {{var "mg"}} {
  46. {{if decElemKindPtr}}{{var "mv"}}, {{var "mok"}} = {{var "v"}}[{{var "mk"}}]
  47. if {{var "mok"}} {
  48. {{var "ms"}} = false
  49. } {{else}}{{var "mv"}} = {{var "v"}}[{{var "mk"}}] {{end}}
  50. } {{if not decElemKindImmutable}}else { {{var "mv"}} = {{decElemZero}} }{{end}}
  51. z.DecSendContainerState(codecSelfer_containerMapValue{{ .Sfx }})
  52. {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ decLineVar $x }}
  53. if {{if decElemKindPtr}} {{var "ms"}} && {{end}} {{var "v"}} != nil {
  54. {{var "v"}}[{{var "mk"}}] = {{var "mv"}}
  55. }
  56. }
  57. } // else len==0: TODO: Should we clear map entries?
  58. z.DecSendContainerState(codecSelfer_containerMapEnd{{ .Sfx }})