goversion_maprange_lt_go112.go 797 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.12
  4. // +build !go1.7 safe
  5. package codec
  6. import "reflect"
  7. type mapIter struct {
  8. m reflect.Value
  9. keys []reflect.Value
  10. j int
  11. values bool
  12. }
  13. func (t *mapIter) ValidKV() (r bool) {
  14. return true
  15. }
  16. func (t *mapIter) Next() (r bool) {
  17. t.j++
  18. return t.j < len(t.keys)
  19. }
  20. func (t *mapIter) Key() reflect.Value {
  21. return t.keys[t.j]
  22. }
  23. func (t *mapIter) Value() (r reflect.Value) {
  24. if t.values {
  25. return t.m.MapIndex(t.keys[t.j])
  26. }
  27. return
  28. }
  29. func (t *mapIter) Done() {}
  30. func mapRange(t *mapIter, m, k, v reflect.Value, values bool) {
  31. *t = mapIter{
  32. m: m,
  33. keys: m.MapKeys(),
  34. values: values,
  35. j: -1,
  36. }
  37. }