goversion_maprange_lt_go112.go 816 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
  2. // Use of this source code is governed by a MIT license found in the LICENSE file.
  3. // +build go1.7
  4. // +build !go1.12
  5. // +build safe appengine
  6. package codec
  7. import "reflect"
  8. type mapIter struct {
  9. m reflect.Value
  10. keys []reflect.Value
  11. j int
  12. values bool
  13. }
  14. func (t *mapIter) ValidKV() (r bool) {
  15. return true
  16. }
  17. func (t *mapIter) Next() (r bool) {
  18. t.j++
  19. return t.j < len(t.keys)
  20. }
  21. func (t *mapIter) Key() reflect.Value {
  22. return t.keys[t.j]
  23. }
  24. func (t *mapIter) Value() (r reflect.Value) {
  25. if t.values {
  26. return t.m.MapIndex(t.keys[t.j])
  27. }
  28. return
  29. }
  30. func (t *mapIter) Done() {}
  31. func mapRange(t *mapIter, m, k, v reflect.Value, values bool) {
  32. *t = mapIter{
  33. m: m,
  34. keys: m.MapKeys(),
  35. values: values,
  36. j: -1,
  37. }
  38. }