// makeMapKeyFromString takes the key type for a map, and a string
// representing the key, it then tries to convert the string
// representation into a value of the correct type.
331724
func makeMapKeyFromString(mapKeyType reflect.Type, pointer string) (reflect.Value, bool) {
	valp := reflect.New(mapKeyType)
	val := reflect.Indirect(valp)
	switch mapKeyType.Kind() {
	case reflect.String:
		return reflect.ValueOf(pointer), true
	case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
		iv, err := strconv.ParseInt(pointer, 10, mapKeyType.Bits())
		if err == nil {
			val.SetInt(iv)
			return val, true
		}
	case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
		iv, err := strconv.ParseUint(pointer, 10, mapKeyType.Bits())
		if err == nil {
			val.SetUint(iv)
			return val, true
		}
	case reflect.Float32, reflect.Float64:
		fv, err := strconv.ParseFloat(pointer, mapKeyType.Bits())
		if err == nil {
			val.SetFloat(fv)
			return val, true
		}
	}

	return reflect.ValueOf(nil), false
}
1048962
func KeyValuesMap(keyvals []interface{}) map[string]interface{} {
	length := len(keyvals) / 2
	vals := make(map[string]interface{}, length)
	for i := 0; i < 2*length; i += 2 {
		vals[StringifyKey(keyvals[i])] = keyvals[i+1]
	}
	return vals
}
1167099
func KeysOfMap(m map[string]string) []string {
	keys := make(sort.StringSlice, len(m))
	i := 0
	for key, _ := range m {
		keys[i] = key
		i++
	}

	keys.Sort()
	return []string(keys)
}
43196
func structFromMap(m map[string]string) *structpb.Struct {
	out := &structpb.Struct{
		Fields: make(map[string]*structpb.Value, len(m)),
	}
	for k, v := range m {
		out.Fields[k] = &structpb.Value{
			Kind: &structpb.Value_StringValue{StringValue: v},
		}
	}
	return out
}
1255799
func StringFromBytes(v []byte) string {
	// In Go 1.3, this string conversion in the map lookup does not allocate
	// to make a new string. We depend on Go 1.3, so this is always free:
	if s, ok := internStr[string(v)]; ok {
		return s
	}
	return string(v)
}
326856
func interfaceToStringMap(obj interface{}) (map[string]string, bool) {
	if obj == nil {
		return nil, false
	}
	lm, ok := obj.(map[string]interface{})
	if !ok {
		return nil, false
	}
	existing := make(map[string]string)
	for k, v := range lm {
		switch t := v.(type) {
		case string:
			existing[k] = t
		}
	}
	return existing, true
}
549003
func (c *Config) GetStringMapString(s string) map[string]string {
	return c.config.GetStringMapString(s)
}
277816
func PrivateKeyFromString(key []byte) (*rsa.PrivateKey, error) {
	block, _ := pem.Decode(key)
	if block == nil {
		return nil, fmt.Errorf("private key block size invalid")
	}
	rsaKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
	if err != nil {
		return nil, err
	}
	return rsaKey, nil
}
421907
func PrettyMap(m Map) string {
	var keys []string
	for k, _ := range m {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	var values []string
	for _, k := range keys {
		values = append(values, fmt.Sprintf("%q: %s", k, m[k]))
	}
	r := strings.Join(values, "\n")
	return fmt.Sprintf("%s", r)
}
531142
func TypeFromString(t string) value.ValueType {
	switch strings.ToLower(t) {
	case "integer":
		// This isn't necessarily true, as integer could be bool
		return value.IntType
	case "real":
		return value.NumberType
	default:
		return value.StringType
	}
}
232185
func CreateMap(values ...interface{}) (map[string]interface{}, error) {
	if len(values)%2 != 0 {
		return nil, errors.New("invalid map call")
	}
	dict := make(map[string]interface{}, len(values)/2)
	for i := 0; i < len(values); i += 2 {
		key, ok := values[i].(string)
		if !ok {
			return nil, errors.New("map keys must be strings")
		}
		dict[key] = values[i+1]
	}
	return dict, nil
}
367765
func ValueFromString(vt string) ValueType {
	switch vt {
	case "nil", "null":
		return NilType
	case "error":
		return ErrorType
	case "unknown":
		return UnknownType
	case "value":
		return ValueInterfaceType
	case "number":
		return NumberType
	case "int":
		return IntType
	case "bool":
		return BoolType
	case "time":
		return TimeType
	case "[]byte":
		return ByteSliceType
	case "string":
		return StringType
	case "[]string":
		return StringsType
	case "map[string]value":
		return MapValueType
	case "map[string]int":
		return MapIntType
	case "map[string]string":
		return MapStringType
	case "map[string]number":
		return MapNumberType
	case "map[string]bool":
		return MapBoolType
	case "map[string]time":
		return MapTimeType
	case "[]value":
		return SliceValueType
	case "struct":
		return StructType
	case "json":
		return JsonType
	default:
		return UnknownType
	}
}
1347476
func GetStringMapValue(mapVal, keyVal interface{}) (interface{}, error) {
	key, ok := keyVal.(string)
	if !ok {
		return nil, trace.BadParameter("only string keys are supported")
	}
	switch m := mapVal.(type) {
	case map[string][]string:
		if len(m) == 0 {
			// to return nil with a proper type
			var n []string
			return n, nil
		}
		return m[key], nil
	case map[string]string:
		if len(m) == 0 {
			return "", nil
		}
		return m[key], nil
	default:
		return nil, trace.BadParameter("type %T is not supported", m)
	}
}
140712
func (s setMap) SetStringMap(key string, value interface{}) {
	// because these methods are meant to be chained without intermediate
	// checks for nil, we are likely to get interfaces with dynamic types but
	// a nil value.
	if reflect.ValueOf(value).IsNil() {
		return
	}

	m := make(map[string]interface{})

	switch value := value.(type) {
	case map[string]string:
		for k, v := range value {
			m[k] = v
		}
	case map[string]*string:
		for k, v := range value {
			if v == nil {
				continue
			}
			m[k] = *v
		}
	case map[string]interface{}:
		for k, v := range value {
			if v == nil {
				continue
			}

			switch v := v.(type) {
			case string:
				m[k] = v
			case *string:
				if v != nil {
					m[k] = *v
				}
			default:
				panic(fmt.Sprintf("unknown type for SetString: %T", v))
			}
		}
	}

	// catch the case where the interface wasn't nil, but we had no non-nil values
	if len(m) > 0 {
		s[key] = m
	}
}
11992
func (s Serializers) SerializeToString(key string, obj interface{}, options ...map[string]interface{}) (string, error) {
	result, err := s.Serialize(key, obj, options...)
	if err != nil {
		return "", err
	}

	return string(result), nil
}
1058295
func parseMap(m Map) (map[int]interface{}, map[string]string) {
	var options = make(map[int]interface{})
	var headers = make(map[string]string)

	if m == nil {
		return options, headers
	}

	for k, v := range m {
		// integer is option
		if kInt, ok := k.(int); ok {
			// don't need to validate
			options[kInt] = v
		} else if kString, ok := k.(string); ok {
			kStringUpper := strings.ToUpper(kString)
			if kInt, ok := CONST[kStringUpper]; ok {
				options[kInt] = v
			} else {
				// it should be header, but we still need to validate it's type
				if vString, ok := v.(string); ok {
					headers[kString] = vString
				}
			}
		}
	}

	return options, headers
}
902615
func (out *DataOutputImpl) WriteStringStringMap(m map[string]string) error {
	if m == nil {
		return out.WriteInt(0)
	}
	err := out.WriteInt(int32(len(m)))
	if err != nil {
		return err
	}
	// enforce key order during serialization
	var keys []string
	for k, _ := range m {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	for _, k := range keys {
		v := m[k]
		// for k, v := range m {
		err = out.WriteString(k)
		if err == nil {
			err = out.WriteString(v)
		}
		if err != nil {
			return err
		}
	}
	return nil
}