open-vault/vendor/github.com/ugorji/go/codec/gen-dec-array.go.tmpl

79 lines
2.8 KiB
Cheetah
Raw Normal View History

2015-10-30 22:07:00 +00:00
{{var "v"}} := {{if not isArray}}*{{end}}{{ .Varname }}
2016-04-26 00:18:04 +00:00
{{var "h"}}, {{var "l"}} := z.DecSliceHelperStart() {{/* // helper, containerLenS */}}{{if not isArray}}
2015-10-30 22:07:00 +00:00
var {{var "c"}} bool {{/* // changed */}}
2016-04-26 00:18:04 +00:00
_ = {{var "c"}}{{end}}
2015-10-30 22:07:00 +00:00
if {{var "l"}} == 0 {
{{if isSlice }}if {{var "v"}} == nil {
{{var "v"}} = []{{ .Typ }}{}
{{var "c"}} = true
} else if len({{var "v"}}) != 0 {
{{var "v"}} = {{var "v"}}[:0]
{{var "c"}} = true
} {{else if isChan }}if {{var "v"}} == nil {
2015-10-30 22:07:00 +00:00
{{var "v"}} = make({{ .CTyp }}, 0)
{{var "c"}} = true
} {{end}}
2017-10-27 19:06:04 +00:00
} else {
{{var "hl"}} := {{var "l"}} > 0
var {{var "rl"}} int
_ = {{var "rl"}}
2017-10-27 19:06:04 +00:00
{{if isSlice }} if {{var "hl"}} {
2015-06-29 21:50:55 +00:00
if {{var "l"}} > cap({{var "v"}}) {
2017-10-27 19:06:04 +00:00
{{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
if {{var "rl"}} <= cap({{var "v"}}) {
{{var "v"}} = {{var "v"}}[:{{var "rl"}}]
2015-10-30 22:07:00 +00:00
} else {
{{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
2015-06-29 21:50:55 +00:00
}
2015-10-30 22:07:00 +00:00
{{var "c"}} = true
2017-10-27 19:06:04 +00:00
} else if {{var "l"}} != len({{var "v"}}) {
2015-10-30 22:07:00 +00:00
{{var "v"}} = {{var "v"}}[:{{var "l"}}]
{{var "c"}} = true
2015-10-07 20:10:00 +00:00
}
2017-10-27 19:06:04 +00:00
} {{end}}
var {{var "j"}} int
// var {{var "dn"}} bool
for ; ({{var "hl"}} && {{var "j"}} < {{var "l"}}) || !({{var "hl"}} || r.CheckBreak()); {{var "j"}}++ {
{{if not isArray}} if {{var "j"}} == 0 && {{var "v"}} == nil {
2017-10-27 19:06:04 +00:00
if {{var "hl"}} {
{{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
} else {
{{var "rl"}} = {{if isSlice}}8{{else if isChan}}64{{end}}
2017-10-27 19:06:04 +00:00
}
{{var "v"}} = make({{if isSlice}}[]{{ .Typ }}{{else if isChan}}{{.CTyp}}{{end}}, {{var "rl"}})
2017-10-27 19:06:04 +00:00
{{var "c"}} = true
}{{end}}
2015-10-30 22:07:00 +00:00
{{var "h"}}.ElemContainerState({{var "j"}})
{{/* {{var "dn"}} = r.TryDecodeAsNil() */}}{{/* commented out, as decLineVar handles this already each time */}}
{{if isChan}}{{ $x := printf "%[1]vvcx%[2]v" .TempVar .Rand }}var {{$x}} {{ .Typ }}
2017-10-27 19:06:04 +00:00
{{ decLineVar $x }}
{{var "v"}} <- {{ $x }}
// println(">>>> sending ", {{ $x }}, " into ", {{var "v"}}) // TODO: remove this
{{else}}{{/* // if indefinite, etc, then expand the slice if necessary */}}
2017-10-27 19:06:04 +00:00
var {{var "db"}} bool
2015-10-30 22:07:00 +00:00
if {{var "j"}} >= len({{var "v"}}) {
{{if isSlice }} {{var "v"}} = append({{var "v"}}, {{ zero }})
{{var "c"}} = true
2017-10-27 19:06:04 +00:00
{{else}} z.DecArrayCannotExpand(len(v), {{var "j"}}+1); {{var "db"}} = true
{{end}}
2015-10-30 22:07:00 +00:00
}
2017-10-27 19:06:04 +00:00
if {{var "db"}} {
2015-06-29 21:50:55 +00:00
z.DecSwallow()
2017-10-27 19:06:04 +00:00
} else {
{{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }}
2015-06-29 21:50:55 +00:00
}
2017-10-27 19:06:04 +00:00
{{end}}
2015-06-29 21:50:55 +00:00
}
2017-10-27 19:06:04 +00:00
{{if isSlice}} if {{var "j"}} < len({{var "v"}}) {
2015-10-30 22:07:00 +00:00
{{var "v"}} = {{var "v"}}[:{{var "j"}}]
{{var "c"}} = true
} else if {{var "j"}} == 0 && {{var "v"}} == nil {
2017-10-27 19:06:04 +00:00
{{var "v"}} = make([]{{ .Typ }}, 0)
2015-10-30 22:07:00 +00:00
{{var "c"}} = true
2017-10-27 19:06:04 +00:00
} {{end}}
2015-06-29 21:50:55 +00:00
}
2015-10-30 22:07:00 +00:00
{{var "h"}}.End()
{{if not isArray }}if {{var "c"}} {
2015-06-29 21:50:55 +00:00
*{{ .Varname }} = {{var "v"}}
2015-10-30 22:07:00 +00:00
}{{end}}