另客网go项目公用的代码库

gen-dec-map.go.tmpl 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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"}}, {{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. r.ReadMapElemKey() {{/* 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. */}}if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} {
  23. {{var "mk"}} = string({{var "bv"}})
  24. }{{ end }}{{if decElemKindPtr}}
  25. {{var "ms"}} = true{{end}}
  26. if {{var "mg"}} {
  27. {{if decElemKindPtr}}{{var "mv"}}, {{var "mok"}} = {{var "v"}}[{{var "mk"}}]
  28. if {{var "mok"}} {
  29. {{var "ms"}} = false
  30. } {{else}}{{var "mv"}} = {{var "v"}}[{{var "mk"}}] {{end}}
  31. } {{if not decElemKindImmutable}}else { {{var "mv"}} = {{decElemZero}} }{{end}}
  32. r.ReadMapElemValue() {{/* z.DecSendContainerState(codecSelfer_containerMapValue{{ .Sfx }}) */}}
  33. {{var "mdn"}} = false
  34. {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ $y := printf "%vmdn%v" .TempVar .Rand }}{{ decLineVar $x $y }}
  35. if {{var "mdn"}} {
  36. if {{ var "bh" }}.DeleteOnNilMapValue { delete({{var "v"}}, {{var "mk"}}) } else { {{var "v"}}[{{var "mk"}}] = {{decElemZero}} }
  37. } else if {{if decElemKindPtr}} {{var "ms"}} && {{end}} {{var "v"}} != nil {
  38. {{var "v"}}[{{var "mk"}}] = {{var "mv"}}
  39. }
  40. }
  41. } // else len==0: TODO: Should we clear map entries?
  42. r.ReadMapEnd() {{/* z.DecSendContainerState(codecSelfer_containerMapEnd{{ .Sfx }}) */}}