예제 #1
0
func keyToProto(k *Key) *pb.Key {
	if k == nil {
		return nil
	}

	// TODO(jbd): Eliminate unrequired allocations.
	path := []*pb.Key_PathElement(nil)
	for {
		el := &pb.Key_PathElement{
			Kind: proto.String(k.kind),
		}
		if k.id != 0 {
			el.Id = proto.Int64(k.id)
		}
		if k.name != "" {
			el.Name = proto.String(k.name)
		}
		path = append([]*pb.Key_PathElement{el}, path...)
		if k.parent == nil {
			break
		}
		k = k.parent
	}
	key := &pb.Key{
		PathElement: path,
	}
	if k.namespace != "" {
		key.PartitionId = &pb.PartitionId{
			Namespace: proto.String(k.namespace),
		}
	}
	return key
}
예제 #2
0
파일: save.go 프로젝트: sfrdmn/camlistore
func interfaceToProto(iv interface{}) (p *pb.Value, errStr string) {
	val := new(pb.Value)
	switch v := iv.(type) {
	case int:
		val.IntegerValue = proto.Int64(int64(v))
	case int32:
		val.IntegerValue = proto.Int64(int64(v))
	case int64:
		val.IntegerValue = proto.Int64(v)
	case bool:
		val.BooleanValue = proto.Bool(v)
	case string:
		val.StringValue = proto.String(v)
	case float32:
		val.DoubleValue = proto.Float64(float64(v))
	case float64:
		val.DoubleValue = proto.Float64(v)
	case *Key:
		if v != nil {
			val.KeyValue = keyToProto(v)
		}
	case time.Time:
		if v.Before(minTime) || v.After(maxTime) {
			return nil, fmt.Sprintf("time value out of range")
		}
		val.TimestampMicrosecondsValue = proto.Int64(toUnixMicro(v))
	case []byte:
		val.BlobValue = v
	default:
		if iv != nil {
			return nil, fmt.Sprintf("invalid Value type %t", iv)
		}
	}
	// TODO(jbd): Support ListValue and EntityValue.
	// TODO(jbd): Support types whose underlying type is one of the types above.
	return val, ""
}
예제 #3
0
func fakeRunQuery(in *pb.RunQueryRequest, out *pb.RunQueryResponse) error {
	expectedIn := &pb.RunQueryRequest{
		Query: &pb.Query{
			Kind: []*pb.KindExpression{&pb.KindExpression{Name: proto.String("Gopher")}},
		},
	}
	if !proto.Equal(in, expectedIn) {
		return fmt.Errorf("unsupported argument: got %v want %v", in, expectedIn)
	}
	*out = pb.RunQueryResponse{
		Batch: &pb.QueryResultBatch{
			MoreResults:      pb.QueryResultBatch_NO_MORE_RESULTS.Enum(),
			EntityResultType: pb.EntityResult_FULL.Enum(),
			EntityResult: []*pb.EntityResult{
				&pb.EntityResult{
					Entity: &pb.Entity{
						Key: key1,
						Property: []*pb.Property{
							{
								Name:  proto.String("Name"),
								Value: &pb.Value{StringValue: proto.String("George")},
							},
							{
								Name: proto.String("Height"),
								Value: &pb.Value{
									IntegerValue: proto.Int64(32),
								},
							},
						},
					},
				},
				&pb.EntityResult{
					Entity: &pb.Entity{
						Key: key2,
						Property: []*pb.Property{
							{
								Name:  proto.String("Name"),
								Value: &pb.Value{StringValue: proto.String("Rufus")},
							},
							// No height for Rufus.
						},
					},
				},
			},
		},
	}
	return nil
}
예제 #4
0
	"io/ioutil"
	"net/http"
	"reflect"
	"testing"

	"camlistore.org/third_party/github.com/golang/protobuf/proto"
	"google.golang.org/cloud"
	pb "google.golang.org/cloud/internal/datastore"
)

var (
	key1 = &pb.Key{
		PathElement: []*pb.Key_PathElement{
			{
				Kind: proto.String("Gopher"),
				Id:   proto.Int64(6),
			},
		},
	}
	key2 = &pb.Key{
		PathElement: []*pb.Key_PathElement{
			{
				Kind: proto.String("Gopher"),
				Id:   proto.Int64(6),
			},
			{
				Kind: proto.String("Gopher"),
				Id:   proto.Int64(8),
			},
		},
	}