...

Source file src/google.golang.org/protobuf/internal/impl/codec_map_go111.go

Documentation: google.golang.org/protobuf/internal/impl

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !go1.12
     6  // +build !go1.12
     7  
     8  package impl
     9  
    10  import "reflect"
    11  
    12  type mapIter struct {
    13  	v    reflect.Value
    14  	keys []reflect.Value
    15  }
    16  
    17  // mapRange provides a less-efficient equivalent to
    18  // the Go 1.12 reflect.Value.MapRange method.
    19  func mapRange(v reflect.Value) *mapIter {
    20  	return &mapIter{v: v}
    21  }
    22  
    23  func (i *mapIter) Next() bool {
    24  	if i.keys == nil {
    25  		i.keys = i.v.MapKeys()
    26  	} else {
    27  		i.keys = i.keys[1:]
    28  	}
    29  	return len(i.keys) > 0
    30  }
    31  
    32  func (i *mapIter) Key() reflect.Value {
    33  	return i.keys[0]
    34  }
    35  
    36  func (i *mapIter) Value() reflect.Value {
    37  	return i.v.MapIndex(i.keys[0])
    38  }
    39  

View as plain text