// DescriptorValue returns the unmarshalled Descriptor field protobuf.
543396
func (s *LogStream) DescriptorValue() (*logpb.LogStreamDescriptor, error) {
	pb := logpb.LogStreamDescriptor{}
	if err := proto.Unmarshal(s.Descriptor, &pb); err != nil {
		return nil, err
	}
	return &pb, nil
}
704701
func IsValue(node Expr) bool {
	switch v := node.(type) {
	case *SQLVal:
		switch v.Type {
		case StrVal, HexVal, IntVal, ValArg:
			return true
		}
	}
	return false
}
780768
func ToValue(v interface{}) Value {
	switch ReflectTypeOf(v) {
	case TIME:
		return NewTimeValue(v)
	default:
		return NewStringValue(v)
	}
}
126826
func (s TypedString) ParseValue() (Value, error) {
	fnc := knownConversions[s.Type.Full()]
	if fnc == nil {
		return s, nil
	}
	return fnc(string(s.Value))
}
1293186
func readingbyValueDescriptorHandler(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()

	vars := mux.Vars(r)
	name, err := url.QueryUnescape(vars["name"])
	// Problems with unescaping URL
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		LoggingClient.Error("Error unescaping value descriptor name: " + err.Error())
		return
	}
	limit, err := strconv.Atoi(vars["limit"])
	// Problems converting limit to int
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		LoggingClient.Error("Error converting the limit to an integer: " + err.Error())
		return
	}

	read, err := getReadingsByValueDescriptor(name, limit)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	encode(read, w)
}
1004394
func (mr *modelRef) fieldValue(name string) reflect.Value {
	return mr.elemValue().FieldByName(name)
}
858342
func valueDescriptorByIdHandler(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()

	vars := mux.Vars(r)
	id := vars["id"]

	switch r.Method {
	case http.MethodGet:
		vd, err := getValueDescriptorById(id)
		if err != nil {
			switch err.(type) {
			case *errors.ErrDbNotFound:
				http.Error(w, err.Error(), http.StatusNotFound)
				return
			default:
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
		}

		encode(vd, w)
	}
}
821501
func (c *Client) ValueDescriptorById(id string) (value contract.ValueDescriptor, err error) {
	conn := c.Pool.Get()
	defer conn.Close()

	err = getObjectById(conn, id, unmarshalObject, &value)
	if err == redis.ErrNil {
		return value, db.ErrNotFound
	}
	if err != nil {
		return value, err
	}

	return value, nil
}
771698
func (mc MongoClient) ValueDescriptorByName(name string) (contract.ValueDescriptor, error) {
	mvd, err := mc.getValueDescriptor(bson.M{"name": name})
	if err != nil {
		return contract.ValueDescriptor{}, err
	}
	return mvd.ToContract(), nil
}
674369
func (o *FlagOption) Descriptor() *OptionDescriptor {
	return &OptionDescriptor{
		Name:        o.Name,
		Description: o.Description,
		Pinned:      o.Pinned,
	}
}
473461
func RawValueFromInterface(i interface{}) (*dosarpc.RawValue, error) {
	// TODO: Do we do type compatibility checks here? We should know the schema,
	// but the callers are all well known and should match the types
	switch v := i.(type) {
	case string:
		return &dosarpc.RawValue{StringValue: &v}, nil
	case bool:
		return &dosarpc.RawValue{BoolValue: &v}, nil
	case int64:
		return &dosarpc.RawValue{Int64Value: &v}, nil
	case int32:
		return &dosarpc.RawValue{Int32Value: &v}, nil
	case float64:
		return &dosarpc.RawValue{DoubleValue: &v}, nil
	case []byte:
		// If we set nil to BinaryValue, thrift cannot encode it
		// as it thought we didn't set any field in the union
		if v == nil {
			v = []byte{}
		}
		return &dosarpc.RawValue{BinaryValue: v}, nil
	case time.Time:
		time := v.UnixNano()
		return &dosarpc.RawValue{Int64Value: &time}, nil
	case dosa.UUID:
		bytes, err := v.Bytes()
		if err != nil {
			return nil, err
		}
		return &dosarpc.RawValue{BinaryValue: bytes}, nil
	case *dosa.UUID:
		if v == nil {
			return nil, nil
		}
		bytes, err := v.Bytes()
		if err != nil {
			return nil, err
		}
		return &dosarpc.RawValue{BinaryValue: bytes}, nil
	case *string:
		if v == nil {
			return nil, nil
		}
		return &dosarpc.RawValue{StringValue: v}, nil
	case *int32:
		if v == nil {
			return nil, nil
		}
		return &dosarpc.RawValue{Int32Value: v}, nil
	case *int64:
		if v == nil {
			return nil, nil
		}
		return &dosarpc.RawValue{Int64Value: v}, nil
	case *float64:
		if v == nil {
			return nil, nil
		}
		return &dosarpc.RawValue{DoubleValue: v}, nil
	case *bool:
		if v == nil {
			return nil, nil
		}
		return &dosarpc.RawValue{BoolValue: v}, nil
	case *time.Time:
		if v == nil {
			return nil, nil
		}
		t := v.UnixNano()
		return &dosarpc.RawValue{Int64Value: &t}, nil
	}
	panic("bad type")
}
1331382
func (mr *modelRef) elemValue() reflect.Value {
	if mr.value().IsNil() {
		msg := fmt.Sprintf("zoom: panic in elemValue(). Model of type %T was nil", mr.model)
		panic(msg)
	}
	return mr.value().Elem()
}
831619
func (self Otto) ToValue(value interface{}) (Value, error) {
	return self.runtime.safeToValue(value)
}
898513
func (ctx *Ctx) MarshalValue() ([]byte, error) {
	if len(ctx.marshalResult.b) > 0 {
		return ctx.marshalResult.b, ctx.marshalResult.err
	}

	if ctx.Printer.marshal == nil {
		return nil, ErrSkipped
	}

	b, err := ctx.Printer.marshal(ctx.Value)
	ctx.marshalResult.b = b
	ctx.marshalResult.err = err
	return b, err
}
491228
func (p *printer) EnumValue(v *descriptor.EnumValueDescriptorProto) {
	p.MaybeLeadingComments(v)
	p.Printf("%s = %d;\n", v.GetName(), v.GetNumber())
}
696781
func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interface{}, depth int) ([]byte, error) {

	switch encType {
	case "address":
		stringValue, ok := encValue.(string)
		if !ok || !common.IsHexAddress(stringValue) {
			return nil, dataMismatchError(encType, encValue)
		}
		retval := make([]byte, 32)
		copy(retval[12:], common.HexToAddress(stringValue).Bytes())
		return retval, nil
	case "bool":
		boolValue, ok := encValue.(bool)
		if !ok {
			return nil, dataMismatchError(encType, encValue)
		}
		if boolValue {
			return math.PaddedBigBytes(common.Big1, 32), nil
		}
		return math.PaddedBigBytes(common.Big0, 32), nil
	case "string":
		strVal, ok := encValue.(string)
		if !ok {
			return nil, dataMismatchError(encType, encValue)
		}
		return crypto.Keccak256([]byte(strVal)), nil
	case "bytes":
		bytesValue, ok := encValue.([]byte)
		if !ok {
			return nil, dataMismatchError(encType, encValue)
		}
		return crypto.Keccak256(bytesValue), nil
	}
	if strings.HasPrefix(encType, "bytes") {
		lengthStr := strings.TrimPrefix(encType, "bytes")
		length, err := strconv.Atoi(lengthStr)
		if err != nil {
			return nil, fmt.Errorf("invalid size on bytes: %v", lengthStr)
		}
		if length < 0 || length > 32 {
			return nil, fmt.Errorf("invalid size on bytes: %d", length)
		}
		if byteValue, ok := encValue.(hexutil.Bytes); !ok {
			return nil, dataMismatchError(encType, encValue)
		} else {
			return math.PaddedBigBytes(new(big.Int).SetBytes(byteValue), 32), nil
		}
	}
	if strings.HasPrefix(encType, "int") || strings.HasPrefix(encType, "uint") {
		length := 0
		if encType == "int" || encType == "uint" {
			length = 256
		} else {
			lengthStr := ""
			if strings.HasPrefix(encType, "uint") {
				lengthStr = strings.TrimPrefix(encType, "uint")
			} else {
				lengthStr = strings.TrimPrefix(encType, "int")
			}
			atoiSize, err := strconv.Atoi(lengthStr)
			if err != nil {
				return nil, fmt.Errorf("invalid size on integer: %v", lengthStr)
			}
			length = atoiSize
		}
		bigIntValue, ok := encValue.(*big.Int)
		if bigIntValue.BitLen() > length {
			return nil, fmt.Errorf("integer larger than '%v'", encType)
		}
		if !ok {
			return nil, dataMismatchError(encType, encValue)
		}
		return abi.U256(bigIntValue), nil
	}
	return nil, fmt.Errorf("unrecognized type '%s'", encType)

}
247988
func valueDescriptorByLabelHandler(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()

	vars := mux.Vars(r)
	label, err := url.QueryUnescape(vars["label"])

	// Problem unescaping
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		LoggingClient.Error("Error unescaping label for the value descriptor: " + err.Error())
		return
	}

	switch r.Method {
	case http.MethodGet:
		v, err := getValueDescriptorsByLabel(label)
		if err != nil {
			switch err.(type) {
			case *errors.ErrDbNotFound:
				http.Error(w, err.Error(), http.StatusNotFound)
				return
			default:
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
		}

		encode(v, w)
	}
}