本文整理匯總了Golang中github.com/dgraph-io/dgraph/types.Geo.UnmarshalBinary方法的典型用法代碼示例。如果您正苦於以下問題:Golang Geo.UnmarshalBinary方法的具體用法?Golang Geo.UnmarshalBinary怎麽用?Golang Geo.UnmarshalBinary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dgraph-io/dgraph/types.Geo
的用法示例。
在下文中一共展示了Geo.UnmarshalBinary方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FilterUids
// FilterUids filters the uids based on the corresponding values and QueryData.
func FilterUids(uids *task.List, values []*task.Value, q *QueryData) *task.List {
x.AssertTruef(len(values) == len(uids.Uids), "lengths not matching")
rv := &task.List{}
for i := 0; i < len(values); i++ {
valBytes := values[i].Val
if bytes.Equal(valBytes, nil) {
continue
}
vType := values[i].ValType
if types.TypeID(vType) != types.GeoID {
continue
}
var g types.Geo
if err := g.UnmarshalBinary(valBytes); err != nil {
continue
}
if !q.MatchesFilter(g) {
continue
}
// we matched the geo filter, add the uid to the list
rv.Uids = append(rv.Uids, uids.Uids[i])
}
return rv
}
示例2: formDataPolygon
func formDataPolygon(t *testing.T, p *geom.Polygon) string {
d, err := wkb.Marshal(p, binary.LittleEndian)
require.NoError(t, err)
var g types.Geo
require.NoError(t, g.UnmarshalBinary(d))
gb, err := g.MarshalText()
require.NoError(t, err)
return string(gb)
}
示例3: formData
func formData(t *testing.T, str string) string {
p, err := loadPolygon(str)
require.NoError(t, err)
d, err := wkb.Marshal(p, binary.LittleEndian)
require.NoError(t, err)
var g types.Geo
require.NoError(t, g.UnmarshalBinary(d))
gb, err := g.MarshalText()
require.NoError(t, err)
return string(gb)
}
示例4: BenchmarkKeyGeneratorPoint
func BenchmarkKeyGeneratorPoint(b *testing.B) {
p := geom.NewPoint(geom.XY).MustSetCoords(geom.Coord{-122.082506, 37.4249518})
data, err := wkb.Marshal(p, binary.LittleEndian)
if err != nil {
b.Error(err)
}
var g types.Geo
g.UnmarshalBinary(data)
b.ResetTimer()
for n := 0; n < b.N; n++ {
IndexTokens(&g)
}
}
示例5: TestKeyGeneratorPolygon
func TestKeyGeneratorPolygon(t *testing.T) {
p, err := loadPolygon("zip.json")
require.NoError(t, err)
data, err := wkb.Marshal(p, binary.LittleEndian)
require.NoError(t, err)
var g types.Geo
err = g.UnmarshalBinary(data)
require.NoError(t, err)
keys, err := IndexTokens(&g)
require.NoError(t, err)
require.Len(t, keys, 65)
}
示例6: TestKeyGeneratorPoint
func TestKeyGeneratorPoint(t *testing.T) {
p := geom.NewPoint(geom.XY).MustSetCoords(geom.Coord{-122.082506, 37.4249518})
data, err := wkb.Marshal(p, binary.LittleEndian)
require.NoError(t, err)
var g types.Geo
err = g.UnmarshalBinary(data)
require.NoError(t, err)
keys, err := IndexTokens(&g)
require.NoError(t, err)
require.Len(t, keys, MaxCellLevel-MinCellLevel+1+1) // +1 for the cover
}
示例7: BenchmarkKeyGeneratorPolygon
func BenchmarkKeyGeneratorPolygon(b *testing.B) {
p, err := loadPolygon("zip.json")
if err != nil {
b.Error(err)
}
data, err := wkb.Marshal(p, binary.LittleEndian)
if err != nil {
b.Error(err)
}
var g types.Geo
g.UnmarshalBinary(data)
b.ResetTimer()
for n := 0; n < b.N; n++ {
IndexTokens(&g)
}
}
示例8: typeValueFromNQuad
func typeValueFromNQuad(nq *graph.NQuad) (types.Value, error) {
if nq.Value == nil || nq.Value.Val == nil {
return nil, nil
}
switch v := nq.Value.Val.(type) {
case *graph.Value_BytesVal:
b := types.Bytes(v.BytesVal)
return &b, nil
case *graph.Value_IntVal:
i := types.Int32(v.IntVal)
return &i, nil
case *graph.Value_StrVal:
s := types.String(v.StrVal)
return &s, nil
case *graph.Value_BoolVal:
b := types.Bool(v.BoolVal)
return &b, nil
case *graph.Value_DoubleVal:
f := types.Float(v.DoubleVal)
return &f, nil
case *graph.Value_GeoVal:
var geom types.Geo
err := geom.UnmarshalBinary(v.GeoVal)
if err != nil {
return nil, err
}
return &geom, nil
case nil:
log.Fatalf("Val being nil is already handled")
return nil, nil
default:
// Unknown type
return nil, x.Errorf("Unknown value type %T", v)
}
}
示例9: TestSchema
func TestSchema(t *testing.T) {
dir, dir2, _ := populateGraph(t)
defer os.RemoveAll(dir)
defer os.RemoveAll(dir2)
query := `
{
debug(_uid_:0x1) {
_xid_
name
gender
alive
loc
friend {
name
}
friend {
}
}
}
`
gq, _, err := gql.Parse(query)
require.NoError(t, err)
ctx := context.Background()
sg, err := ToSubGraph(ctx, gq)
require.NoError(t, err)
ch := make(chan error)
go ProcessGraph(ctx, sg, nil, ch)
err = <-ch
require.NoError(t, err)
var l Latency
gr, err := sg.ToProtocolBuffer(&l)
require.NoError(t, err)
require.EqualValues(t, "debug", gr.Children[0].Attribute)
require.EqualValues(t, 1, gr.Children[0].Uid)
require.EqualValues(t, "mich", gr.Children[0].Xid)
require.Len(t, gr.Children[0].Properties, 4)
require.EqualValues(t, "Michonne",
getProperty(gr.Children[0].Properties, "name").GetStrVal())
var g types.Geo
x.Check(g.UnmarshalBinary(getProperty(gr.Children[0].Properties, "loc").GetGeoVal()))
received, err := g.MarshalText()
require.EqualValues(t, "{'type':'Point','coordinates':[1.1,2]}", string(received))
require.Len(t, gr.Children[0].Children, 5)
child := gr.Children[0].Children[0]
require.EqualValues(t, 23, child.Uid)
require.EqualValues(t, "friend", child.Attribute)
require.Len(t, child.Properties, 1)
require.EqualValues(t, "Rick Grimes",
getProperty(child.Properties, "name").GetStrVal())
require.Empty(t, child.Children)
child = gr.Children[0].Children[1]
require.EqualValues(t, 24, child.Uid)
require.EqualValues(t, "friend", child.Attribute)
require.Len(t, child.Properties, 1)
require.EqualValues(t, "Glenn Rhee",
getProperty(child.Properties, "name").GetStrVal())
require.Empty(t, child.Children)
child = gr.Children[0].Children[4]
require.EqualValues(t, 101, child.Uid)
require.EqualValues(t, "friend", child.Attribute)
require.Len(t, child.Properties, 0)
}