// Handle the encoding of an arbritary map[K]V
506820
func (en *encoder) handleMap(key uint64, mpval reflect.Value, prefix TagPrefix) {
	/*
		A map defined as
			map<key_type, value_type> map_field = N;
		is encoded in the same way as
			message MapFieldEntry {
				key_type key = 1;
				value_type value = 2;
			}
			repeated MapFieldEntry map_field = N;
	*/

	for _, mkey := range mpval.MapKeys() {
		mval := mpval.MapIndex(mkey)

		// illegal map entry values
		// - nil message pointers.
		switch kind := mval.Kind(); kind {
		case reflect.Ptr:
			if mval.IsNil() {
				panic("proto: map has nil element")
			}
		case reflect.Slice, reflect.Array:
			if mval.Type().Elem().Kind() != reflect.Uint8 {
				panic("protobuf: map only support []byte or string as repeated value")
			}
		}

		packed := encoder{}
		packed.value(1<<3, mkey, prefix)
		packed.value(2<<3, mval, prefix)

		en.uvarint(key | 2)
		b := packed.Bytes()
		en.uvarint((uint64(len(b))))
		en.Write(b)
	}
}
1155772
func (o *OvsMap) UnmarshalJSON(b []byte) (err error) {
	var oMap []interface{}
	o.GoMap = make(map[interface{}]interface{})
	if err := json.Unmarshal(b, &oMap); err == nil && len(oMap) > 1 {
		innerSlice := oMap[1].([]interface{})
		for _, val := range innerSlice {
			f := val.([]interface{})
			o.GoMap[f[0]] = f[1]
		}
	}
	return err
}
950006
func toMap(kv ...string) map[string]string {
	if len(kv)%2 != 0 {
		common.Die("Expected even number of strings in toMap")
	}
	r := make(map[string]string, len(kv))
	lastKey := ""
	for i, kv := range kv {
		if i%2 == 0 {
			lastKey = kv
		} else {
			r[lastKey] = kv
		}
	}
	return r
}
420650
func (a Annotation) ToMap() map[string]string {
	out := make(map[string]string)
	for k, v := range a {
		out[k] = v
	}
	return out
}
813450
func (this Map) MustEncode() BSON {
	b, err := encodeMap("", this)
	if err != nil {
		panic(err)
	}
	return b
}
207855
func Uint64ValueMap(src map[string]*uint64) map[string]uint64 {
	dst := make(map[string]uint64)
	for k, val := range src {
		if val != nil {
			dst[k] = *val
		}
	}
	return dst
}
918446
func (h *contextualHandler) Handle(err error) {
	err = With(err, h.keyvals...)

	h.handler.Handle(err)
}
242416
func (mux *TypeMux) Handle(t Type, h Handler) {
	mux.mux.Handle(TypeMatcher(t), h)
}
129758
func Compresses(exts []string) HandlerFunc {
	extsmap := make(map[string]bool)
	for _, ext := range exts {
		extsmap[strings.ToLower(ext)] = true
	}

	return func(ctx *Context) {
		ae := ctx.Req().Header.Get("Accept-Encoding")
		if ae == "" {
			ctx.Next()
			return
		}

		if len(extsmap) > 0 {
			ext := strings.ToLower(path.Ext(ctx.Req().URL.Path))
			if _, ok := extsmap[ext]; ok {
				compress(ctx, "auto")
				return
			}
		}

		if action := ctx.Action(); action != nil {
			if c, ok := action.(Compresser); ok {
				compress(ctx, c.CompressType())
				return
			}
		}

		// if blank, then no compress
		ctx.Next()
	}
}
290398
func ToMap(in interface{}, pivot string) interface{} {
	value := reflect.ValueOf(in)

	// input value must be a slice
	if value.Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v must be a slice", in))
	}

	inType := value.Type()

	structType := inType.Elem()

	// retrieve the struct in the slice to deduce key type
	if structType.Kind() == reflect.Ptr {
		structType = structType.Elem()
	}

	field, _ := structType.FieldByName(pivot)

	// value of the map will be the input type
	collectionType := reflect.MapOf(field.Type, inType.Elem())

	// create a map from scratch
	collection := reflect.MakeMap(collectionType)

	for i := 0; i < value.Len(); i++ {
		instance := value.Index(i)
		var field reflect.Value

		if instance.Kind() == reflect.Ptr {
			field = instance.Elem().FieldByName(pivot)
		} else {
			field = instance.FieldByName(pivot)
		}

		collection.SetMapIndex(field, instance)
	}

	return collection.Interface()
}
360732
func (jsonEncoderDecoder) Decode(data []byte, v interface{}) error {
	return json.Unmarshal(data, v)
}
231005
func YAMLHandler(front string) (map[string]interface{}, error) {
	out := make(map[string]interface{})
	err := yaml.Unmarshal([]byte(front), out)
	if err != nil {
		return nil, err
	}
	return out, nil
}
324053
func (fn PetUploadImageHandlerFunc) Handle(params PetUploadImageParams, principal interface{}) middleware.Responder {
	return fn(params, principal)
}
1112557
func sliceOrMap2ExpandedSlice(value interface{}) []string {
	var result []string
	expandedStringOrPanic := func(v interface{}) string {
		switch concreteValue := v.(type) {
		case []interface{}: // YAML or JSON
			panic(StatusError{fmt.Errorf("unknown type: %v", v), 65})
		case map[interface{}]interface{}: // YAML
			panic(StatusError{fmt.Errorf("unknown type: %v", v), 65})
		case map[string]interface{}: // JSON
			panic(StatusError{fmt.Errorf("unknown type: %v", v), 65})
		default:
			return expandEnv(fmt.Sprintf("%v", concreteValue))
		}
	}
	if value != nil {
		switch concreteValue := value.(type) {
		case []interface{}: // YAML or JSON: array
			for _, v := range concreteValue {
				result = append(result, expandedStringOrPanic(v))
			}
		case map[interface{}]interface{}: // YAML: hash
			for k, v := range concreteValue {
				result = append(result, expandedStringOrPanic(k)+"="+expandedStringOrPanic(v))
			}
		case map[string]interface{}: // JSON: hash
			for k, v := range concreteValue {
				result = append(result, expandEnv(k)+"="+expandedStringOrPanic(v))
			}
		default:
			panic(StatusError{fmt.Errorf("unknown type: %v", value), 65})
		}
	}
	return result
}
830830
func (hdr *Handler) Handle(im *imageserver.Image, params imageserver.Params) (*imageserver.Image, error) {
	if im.Format != "gif" {
		return nil, &imageserver.ImageError{Message: fmt.Sprintf("image format is not gif: %s", im.Format)}
	}
	if !hdr.Processor.Change(params) {
		return im, nil
	}
	g, err := gif.DecodeAll(bytes.NewReader(im.Data))
	if err != nil {
		return nil, &imageserver.ImageError{Message: err.Error()}
	}
	g, err = hdr.Processor.Process(g, params)
	if err != nil {
		return nil, err
	}
	buf := new(bytes.Buffer)
	err = gif.EncodeAll(buf, g)
	if err != nil {
		return nil, &imageserver.ImageError{Message: err.Error()}
	}
	im = &imageserver.Image{
		Format: "gif",
		Data:   buf.Bytes(),
	}
	return im, nil
}
1152183
func DecodeTLV(r *bytes.Buffer) (Map, error) {
	t := make(Map)
	for r.Len() >= 4 {
		b := r.Next(4)
		ft := Tag(binary.BigEndian.Uint16(b[0:2]))
		fl := binary.BigEndian.Uint16(b[2:4])
		if r.Len() < int(fl) {
			return nil, fmt.Errorf("not enough data for tag %s: want %d, have %d",
				ft.Hex(), fl, r.Len())
		}
		b = r.Next(int(fl))
		t[ft] = &Field{
			Tag:  ft,
			Data: b,
		}
	}
	return t, nil
}
492627
func (c *APIAddressUpdater) Handle(_ <-chan struct{}) error {
	hpsToSet, err := c.getAddresses()
	if err != nil {
		return err
	}
	logger.Debugf("updating API hostPorts to %+v", hpsToSet)
	c.mu.Lock()
	c.current = hpsToSet
	c.mu.Unlock()
	if err := c.setter.SetAPIHostPorts(hpsToSet); err != nil {
		return fmt.Errorf("error setting addresses: %v", err)
	}
	return nil
}