// ToProperty implements datastore.PropertyConverter. It causes an embedded
// 'BugTemplate' to serialize to an unindexed '[]byte' when used with the
// "go.chromium.org/gae" library.
508760
func (p *BugTemplate) ToProperty() (prop datastore.Property, err error) {
	data, err := proto.Marshal(p)
	if err == nil {
		prop.SetValue(data, datastore.NoIndex)
	}
	return
}
531145
func (p *propertySet) populateProperties(allocs []*structs.Allocation, nodes map[string]*structs.Node,
	properties map[string]uint64) {

	for _, alloc := range allocs {
		nProperty, ok := getProperty(nodes[alloc.NodeID], p.targetAttribute)
		if !ok {
			continue
		}

		properties[nProperty]++
	}
}
182869
func (b *SampleJSONBuilder) Properties() []*SamplePropertyInfo {
	return []*SamplePropertyInfo{
		b.B,
		b.C,
		b.D,
		b.E,
	}
}
180471
func (p *BugTemplate) FromProperty(prop datastore.Property) error {
	data, err := prop.Project(datastore.PTBytes)
	if err != nil {
		return err
	}
	return proto.Unmarshal(data.([]byte), p)
}
337430
func (bf *BitField) FromProperty(p datastore.Property) error {
	bin, ok := p.Value().([]byte)
	if !ok {
		return fmt.Errorf("expected %s, got %s", datastore.PTBytes, p.Type())
	}
	return bf.UnmarshalBinary(bin)
}
734719
func (dp *Datapoint) SetProperty(key string, value interface{}) {
	if dp.Meta[tsProperty] == nil {
		dp.Meta[tsProperty] = make(map[string]interface{}, 1)
	}
	dp.GetProperties()[key] = value
}
167585
func NewProperties(in interface{}, context *compiler.Context) (*Properties, error) {
	errors := make([]error, 0)
	x := &Properties{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		// repeated NamedSchemaOrReference additional_properties = 1;
		// MAP: SchemaOrReference
		x.AdditionalProperties = make([]*NamedSchemaOrReference, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				pair := &NamedSchemaOrReference{}
				pair.Name = k
				var err error
				pair.Value, err = NewSchemaOrReference(v, compiler.NewContext(k, context))
				if err != nil {
					errors = append(errors, err)
				}
				x.AdditionalProperties = append(x.AdditionalProperties, pair)
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
719301
func (m *ManifestLink) ToProperty() (ds.Property, error) {
	buf := bytes.NewBuffer(nil)
	cmpbin.WriteString(buf, m.Name)
	cmpbin.WriteBytes(buf, m.ID)
	return ds.MkProperty(buf.Bytes()), nil
}
1070260
func GetProperties(required bool) (*Properties, error) {
	filename := flag.String("props", "", "properties filename")
	flag.Parse()
	if *filename == "" {
		if required {
			return nil, NO_PROPS_FILE
		} else {
			return &Properties{make(map[string]string)}, nil
		}
	}
	return readPropertiesFile(*filename)
}
875278
func (p Property) Schema(name, parent string) string {

	// Open the schema template and setup a counter function that will
	// available in the template to be used to detect when trailing commas
	// are required in the JSON when looping through maps
	tmpl, err := template.New("schema-property.template").Funcs(template.FuncMap{
		"counter":           counter,
		"convertToJSONType": convertTypeToJSON,
	}).ParseFiles("generate/templates/schema-property.template")

	var buf bytes.Buffer
	parentpaths := strings.Split(parent, ".")

	templateData := struct {
		Name     string
		Parent   string
		Property Property
	}{
		Name:     name,
		Parent:   parentpaths[0],
		Property: p,
	}

	// Execute the template, writing it to the buffer
	err = tmpl.Execute(&buf, templateData)
	if err != nil {
		fmt.Printf("Error: Failed to generate property %s\n%s\n", name, err)
		os.Exit(1)
	}

	return buf.String()

}
911802
func properties(props *structpb.Struct) []property {
	if props == nil {
		return nil
	}
	// Render the fields to JSON.
	m := jsonpb.Marshaler{}
	buf := bytes.NewBuffer(nil)
	if err := m.Marshal(buf, props); err != nil {
		panic(err) // This shouldn't happen.
	}
	d := json.NewDecoder(buf)
	jsonProps := map[string]json.RawMessage{}
	if err := d.Decode(&jsonProps); err != nil {
		panic(err) // This shouldn't happen.
	}

	// Sort the names.
	names := make([]string, 0, len(jsonProps))
	for n := range jsonProps {
		names = append(names, n)
	}
	sort.Strings(names)

	// Rearrange the fields into a slice.
	results := make([]property, len(jsonProps))
	for i, n := range names {
		buf.Reset()
		json.Indent(buf, jsonProps[n], "", "  ")
		results[i] = property{
			Name:  n,
			Value: buf.String(),
		}
	}
	return results
}
345218
func propByIndex(t reflect.Type, x []int) *Properties {
	if len(x) != 1 {
		fmt.Fprintf(os.Stderr, "proto: field index dimension %d (not 1) for type %s\n", len(x), t)
		return nil
	}
	prop := GetProperties(t)
	return prop.Prop[x[0]]
}
63482
func (m *GenericParser) getProperty(mapKey reflect.Value) (Property, error) {
	properteerType := reflect.TypeOf(new(Properteer)).Elem()
	stringerType := reflect.TypeOf(new(fmt.Stringer)).Elem()

	// if mapKey implements the pdk.Properteer interface, use that.
	if k2, ok := anyImplements(mapKey, properteerType); ok {
		return k2.Interface().(Properteer).Property(), nil
	}
	// if mapKey implements fmt.Stringer, use that.
	if k2, ok := anyImplements(mapKey, stringerType); ok {
		return Property(k2.Interface().(fmt.Stringer).String()), nil
	}

	// Otherwise, handle all comparable types (see https://golang.org/ref/spec#Comparison_operators):
	mapKey = deref(mapKey)
	switch k := mapKey.Kind(); k {
	case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
		return Property(fmt.Sprintf("%v", mapKey)), nil
	case reflect.Chan:
		m.Stats.Count("parser.getProperty.Chan", 1, 1)
		return "", errors.New("channel cannot be converted to property")
	case reflect.Array:
		m.Stats.Count("parser.getProperty."+k.String(), 1, 1)
		return "", errors.New("array cannot be converted to property")
	case reflect.Struct:
		m.Stats.Count("parser.getProperty."+k.String(), 1, 1)
		return "", errors.New("struct cannot be converted to property")
	case reflect.Complex128, reflect.Complex64:
		m.Stats.Count("parser.getProperty."+k.String(), 1, 1)
		return "", errors.New("complex value cannot be converted to property")
	default:
		m.Stats.Count("parser.getProperty."+k.String(), 1, 1)
		return "", errors.Errorf("unexpected kind: %v mapKey: %v", mapKey.Kind(), mapKey)
	}
}
885327
func (cps ComparablePrincipalSet) ToPrincipalSet() policies.PrincipalSet {
	var res policies.PrincipalSet
	for _, cp := range cps {
		res = append(res, cp.principal)
	}
	return res
}
32079
func jsonProperties(f reflect.StructField, origName bool) *proto.Properties {
	var prop proto.Properties
	prop.Init(f.Type, f.Name, f.Tag.Get("protobuf"), &f)
	if origName || prop.JSONName == "" {
		prop.JSONName = prop.OrigName
	}
	return &prop
}
1288636
func (s Session) GetProperty(key string, value interface{}) (interface{}, error) {
	// Capitalize the first letter
	key = strings.Title(key)

	sessionLog.Info("getProperty", "key", key, "value", value)

	// For a map it is easy
	if reflect.TypeOf(value).Kind() == reflect.Map {
		val := reflect.ValueOf(value)
		valueOf := val.MapIndex(reflect.ValueOf(key))
		if valueOf == reflect.Zero(reflect.ValueOf(value).Type()) {
			return nil, nil
		}
		//idx := val.MapIndex(reflect.ValueOf(key))
		if !valueOf.IsValid() {
			return nil, nil
		}

		return valueOf.Interface(), nil
	}

	objValue := s.reflectValue(value)
	field := objValue.FieldByName(key)
	if !field.IsValid() {
		return nil, SESSION_VALUE_NOT_FOUND
	}

	return field.Interface(), nil
}
1122267
func (p *Post) GetProperty(key string) (interface{}, error) {
	if field, exists := reflect.TypeOf(p).Elem().FieldByName(key); exists {
		return reflect.ValueOf(p).Elem().FieldByIndex(field.Index), nil
	}
	return nil, errors.New(fmt.Sprintf("Property %s does not exist", key))
}