示例#1
0
文件: load.go 项目: yschu7/go_test
func protoToProperties(dst chan<- Property, errc chan<- error, src *pb.EntityProto) {
	defer close(dst)
	props, rawProps := src.Property, src.RawProperty
	for {
		var (
			x       *pb.Property
			noIndex bool
		)
		if len(props) > 0 {
			x, props = props[0], props[1:]
		} else if len(rawProps) > 0 {
			x, rawProps = rawProps[0], rawProps[1:]
			noIndex = true
		} else {
			break
		}

		var value interface{}
		switch {
		case x.Value.Int64Value != nil:
			if x.Meaning != nil && *x.Meaning == pb.Property_GD_WHEN {
				value = fromUnixMicro(*x.Value.Int64Value)
			} else {
				value = *x.Value.Int64Value
			}
		case x.Value.BooleanValue != nil:
			value = *x.Value.BooleanValue
		case x.Value.StringValue != nil:
			if x.Meaning != nil && *x.Meaning == pb.Property_BLOB {
				value = []byte(*x.Value.StringValue)
			} else if x.Meaning != nil && *x.Meaning == pb.Property_BLOBKEY {
				value = appengine.BlobKey(*x.Value.StringValue)
			} else {
				value = *x.Value.StringValue
			}
		case x.Value.DoubleValue != nil:
			value = *x.Value.DoubleValue
		case x.Value.Referencevalue != nil:
			key, err := referenceValueToKey(x.Value.Referencevalue)
			if err != nil {
				errc <- err
				return
			}
			value = key
		}
		dst <- Property{
			Name:     x.GetName(),
			Value:    value,
			NoIndex:  noIndex,
			Multiple: x.GetMultiple(),
		}
	}
	errc <- nil
}
示例#2
0
func protoToProperties(dst chan<- Property, errc chan<- error, src *pb.EntityProto) {
	defer close(dst)
	props, rawProps := src.Property, src.RawProperty
	for {
		var (
			x       *pb.Property
			noIndex bool
		)
		if len(props) > 0 {
			x, props = props[0], props[1:]
		} else if len(rawProps) > 0 {
			x, rawProps = rawProps[0], rawProps[1:]
			noIndex = true
		} else {
			break
		}

		var value interface{}
		if x.Meaning != nil && *x.Meaning == pb.Property_INDEX_VALUE {
			value = indexValue{x.Value}
		} else {
			var err error
			value, err = propValue(x.Value, x.GetMeaning())
			if err != nil {
				errc <- err
				return
			}
		}
		dst <- Property{
			Name:     x.GetName(),
			Value:    value,
			NoIndex:  noIndex,
			Multiple: x.GetMultiple(),
		}
	}
	errc <- nil
}