github.com/cayleygraph/cayley@v0.7.7/graph/proto/primitive_helpers.go (about) 1 package proto 2 3 import "github.com/cayleygraph/quad" 4 5 //go:generate protoc --proto_path=$GOPATH/src:. --gogo_out=. primitive.proto 6 7 func (p Primitive) GetDirection(d quad.Direction) uint64 { 8 switch d { 9 case quad.Subject: 10 return p.Subject 11 case quad.Predicate: 12 return p.Predicate 13 case quad.Object: 14 return p.Object 15 case quad.Label: 16 return p.Label 17 } 18 panic("unknown direction") 19 } 20 21 func (p *Primitive) SetDirection(d quad.Direction, v uint64) { 22 switch d { 23 case quad.Subject: 24 p.Subject = v 25 case quad.Predicate: 26 p.Predicate = v 27 case quad.Object: 28 p.Object = v 29 case quad.Label: 30 p.Label = v 31 } 32 } 33 34 func (p Primitive) IsNode() bool { 35 return len(p.Value) != 0 36 } 37 38 func (p Primitive) Key() interface{} { 39 return p.ID 40 } 41 42 func (p *Primitive) IsSameLink(q *Primitive) bool { 43 return p.Subject == q.Subject && p.Predicate == q.Predicate && p.Object == q.Object && p.Label == q.Label 44 }