//go:generate protoc --proto_path=$GOPATH/src:. --gogo_out=. quads.proto
// MakeValue converts quad.Value to its protobuf representation.
329158
func MakeValue(qv quad.Value) *Value {
	if qv == nil {
		return nil
	}
	switch v := qv.(type) {
	//case quad.Raw:
	//	return &Value{&Value_Raw{[]byte(v)}}
	case quad.String:
		return &Value{&Value_Str{string(v)}}
	case quad.IRI:
		return &Value{&Value_Iri{string(v)}}
	case quad.BNode:
		return &Value{&Value_Bnode{string(v)}}
	case quad.TypedString:
		return &Value{&Value_TypedStr{&Value_TypedString{
			Value: string(v.Value),
			Type:  string(v.Type),
		}}}
	case quad.LangString:
		return &Value{&Value_LangStr{&Value_LangString{
			Value: string(v.Value),
			Lang:  v.Lang,
		}}}
	case quad.Int:
		return &Value{&Value_Int{int64(v)}}
	case quad.Float:
		return &Value{&Value_Float{float64(v)}}
	case quad.Bool:
		return &Value{&Value_Boolean{bool(v)}}
	case quad.Time:
		t := time.Time(v)
		seconds := t.Unix()
		nanos := int32(t.Sub(time.Unix(seconds, 0)))
		return &Value{&Value_Time{&Value_Timestamp{
			Seconds: seconds,
			Nanos:   nanos,
		}}}
	default:
		panic(fmt.Errorf("unsupported type: %T", qv))
	}
}
581107
func MakePreimage(newPreimage []byte) (Preimage, error) {
	nhlen := len(newPreimage)
	if nhlen != PreimageSize {
		return Preimage{}, fmt.Errorf("invalid preimage length of %v, "+
			"want %v", nhlen, PreimageSize)
	}

	var preimage Preimage
	copy(preimage[:], newPreimage)

	return preimage, nil
}
402513
func (g RemoteValueGenerator) GenerateValue(expression string) (interface{}, error) {
	matches := remoteExp.FindAllStringIndex(expression, -1)
	if len(matches) < 1 {
		return expression, fmt.Errorf("no matches found.")
	}
	for _, r := range matches {
		response, err := http.Get(expression[5 : len(expression)-1])
		if err != nil {
			return "", err
		}
		defer response.Body.Close()
		body, err := ioutil.ReadAll(response.Body)
		if err != nil {
			return "", err
		}
		expression = strings.Replace(expression, expression[r[0]:r[1]], strings.TrimSpace(string(body)), 1)
	}
	return expression, nil
}
499262
func makeParams(rt reflect.Type, rv reflect.Value) []interface{} {
	numFields := rt.NumField()
	params := make([]interface{}, 0, numFields)
	for i := 0; i < numFields; i++ {
		rtf := rt.Field(i)
		rvf := rv.Field(i)
		if rtf.Type.Kind() == reflect.Ptr {
			if rvf.IsNil() {
				break
			}
			rvf.Elem()
		}
		params = append(params, rvf.Interface())
	}

	return params
}
330791
func (ppm *ProtoProducerMessage) GetValue(msg proto.Message) error {
	err := ppm.Serializer.Unmarshal(ppm.ProducerMessage.GetValue(), msg)
	if err != nil {
		return err
	}
	return nil
}
464507
func MakeField(name string, value interface{}, ftype FieldType) Field {
	f := Field{Name: name, Value: ValueOf(value)}
	f.setType(ftype)
	return f
}
1153770
func (r *ProtoKeyValWrapper) GetValue(value proto.Message) error {
	err := r.ProtoKeyVal.GetValue(value)
	if err != nil {
		return err
	}
	_, err = r.decrypter.Decrypt(value, r.decryptFunc)
	return err
}
1214127
func (gc *GeometryCollection) Value() (driver.Value, error) {
	if gc.GeometryCollection == nil {
		return nil, nil
	}
	return value(gc.GeometryCollection)
}
772357
func protoc(goOut string, includes, fnames []string) ([]byte, error) {
	args := []string{"--go_out=plugins=grpc:" + goOut}
	for _, inc := range includes {
		args = append(args, "-I", inc)
	}
	args = append(args, fnames...)
	return exec.Command("protoc", args...).CombinedOutput()
}
1112797
func ProtoToValue(v *querypb.Value) Value {
	return MakeTrusted(v.Type, v.Value)
}
1348236
func (iter *UnionIter) Value() []byte {
	if !iter.curIsDirty {
		return iter.snapshotIt.Value()
	}
	return iter.dirtyIt.Value()
}
1317243
func MakeMiniPath(fileName ...string) string {
	args := []string{GetMinipath()}
	args = append(args, fileName...)
	return filepath.Join(args...)
}
876505
func (s *Shape) GoStructValueType(name string, ref *ShapeRef) string {
	v := s.GoStructType(name, ref)

	if ref.UseIndirection() && v[0] == '*' {
		return v[1:]
	}

	return v
}
634113
func (p Path) Value() (driver.Value, error) {
	op := []string{}
	for _, x := range p {
		op = append(op, ConvertToLtree(x))
	}
	s := strings.Join(op, SepInDatabase)
	return s, nil
}
1367523
func GValueFromNative(value interface{}) *C.GValue {
	var gv *C.GValue

	if _, ok := value.(WrappedObject); ok {
		value = value.(WrappedObject).GetInternalValue()
	}
	if _, ok := value.(GObject); ok {
		value = value.(GObject).Object
	}
	if _, ok := value.(GValue); ok {
		value = value.(GValue).Value
	}

	switch value.(type) {
	case bool:
		gv = C.init_gvalue_bool(gbool(value.(bool)))
		break
	case byte:
		gv = C.init_gvalue_byte(C.guchar(value.(byte)))
		break
	case int:
		gv = C.init_gvalue_int(C.gint(value.(int)))
		break
	case uint:
		gv = C.init_gvalue_uint(C.guint(value.(uint)))
		break
	case int64:
		gv = C.init_gvalue_int64(C.gint64(value.(int64)))
		break
	case float32:
		gv = C.init_gvalue_double(C.gdouble(value.(float32)))
		break
	case float64:
		gv = C.init_gvalue_double(C.gdouble(value.(float64)))
		break
	case string:
		{
			pval := C.CString(value.(string))
			defer C.free_string(pval)
			gv = C.init_gvalue_string(C.to_gcharptr(pval))
		}
		break
	default:
		//gv = C.init_gvalue_pointer(C.gpointer(unsafe.Pointer(&value)));
		break
	}
	return gv
}
177658
func toValue(p interface{}) reflect.Value {
	v := reflect.ValueOf(p)
	if v.Kind() == reflect.Ptr {
		v = v.Elem()
	}
	return v
}
696532
func fieldValue(fieldVal reflect.Value, structField reflect.StructField) (ret interface{}) {
	if isBlank(fieldVal) {
		defaultValue := strings.TrimSpace(parseTagSetting(structField.Tag.Get("sql"))["default"])
		if defaultValue != "" {
			switch fieldVal.Kind() {
			case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
				if numericValue, err := strconv.ParseInt(defaultValue, 10, 64); err == nil {
					if numericValue != fieldVal.Int() {
						return fieldVal.Int()
					}
					return numericValue
				}
			case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
				if numericValue, err := strconv.ParseUint(defaultValue, 10, 64); err == nil {
					if numericValue != fieldVal.Uint() {
						return fieldVal.Int()
					}
					return numericValue
				}
			case reflect.Float32, reflect.Float64:
				if floatValue, err := strconv.ParseFloat(defaultValue, 64); err == nil {
					if floatValue != fieldVal.Float() {
						return fieldVal.Float()
					}
					return floatValue
				}
			case reflect.Bool:
				if boolValue, err := strconv.ParseBool(defaultValue); err == nil {
					if boolValue != fieldVal.Bool() {
						return fieldVal.Bool()
					}
					return boolValue
				}
			case reflect.String:
				return fieldVal.String()
			default:
				return nil
			}
		}
		return nil
	}
	return fieldVal.Interface()
}