本文整理匯總了Golang中github.com/dgraph-io/dgraph/posting/types.Posting.ValueBytes方法的典型用法代碼示例。如果您正苦於以下問題:Golang Posting.ValueBytes方法的具體用法?Golang Posting.ValueBytes怎麽用?Golang Posting.ValueBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dgraph-io/dgraph/posting/types.Posting
的用法示例。
在下文中一共展示了Posting.ValueBytes方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExternalId
func ExternalId(uid uint64) (xid string, rerr error) {
key := posting.Key(uid, "_xid_") // uid -> "_xid_" -> xid
pl := posting.GetOrCreate(key, uidStore)
if pl.Length() == 0 {
return "", errors.New("NO external id")
}
if pl.Length() > 1 {
glog.WithField("uid", uid).Fatal("This shouldn't be happening.")
return "", errors.New("Multiple external ids for this uid.")
}
var p types.Posting
if ok := pl.Get(&p, 0); !ok {
glog.WithField("uid", uid).Error("While retrieving posting")
return "", errors.New("While retrieving posting")
}
if p.Uid() != math.MaxUint64 {
glog.WithField("uid", uid).Fatal("Value uid must be MaxUint64.")
}
var t interface{}
rerr = posting.ParseValue(&t, p.ValueBytes())
xid = t.(string)
return xid, rerr
}
示例2: samePosting
func samePosting(a *types.Posting, b *types.Posting) bool {
if a.Uid() != b.Uid() {
return false
}
if a.ValueLength() != b.ValueLength() {
return false
}
if !bytes.Equal(a.ValueBytes(), b.ValueBytes()) {
return false
}
if !bytes.Equal(a.Source(), b.Source()) {
return false
}
return true
}
示例3: allocateUniqueUid
func allocateUniqueUid(xid string, instanceIdx uint64,
numInstances uint64) (uid uint64, rerr error) {
mod := math.MaxUint64 / numInstances
minIdx := instanceIdx * mod
for sp := ""; ; sp += " " {
txid := xid + sp
uid1 := farm.Fingerprint64([]byte(txid)) // Generate from hash.
uid = (uid1 % mod) + minIdx
glog.WithField("txid", txid).WithField("uid", uid).Debug("Generated")
if uid == math.MaxUint64 {
glog.Debug("Hit uint64max while generating fingerprint. Ignoring...")
continue
}
// Check if this uid has already been allocated.
key := posting.Key(uid, "_xid_") // uid -> "_xid_" -> xid
pl := posting.GetOrCreate(key, uidStore)
if pl.Length() > 0 {
// Something already present here.
var p types.Posting
pl.Get(&p, 0)
var tmp interface{}
posting.ParseValue(&tmp, p.ValueBytes())
glog.Debug("Found existing xid: [%q]. Continuing...", tmp.(string))
continue
}
// Uid hasn't been assigned yet.
t := x.DirectedEdge{
Value: xid, // not txid
Source: "_assigner_",
Timestamp: time.Now(),
}
rerr = pl.AddMutation(t, posting.Set)
if rerr != nil {
glog.WithError(rerr).Error("While adding mutation")
}
return uid, rerr
}
return 0, errors.New("Some unhandled route lead me here." +
" Wake the stupid developer up.")
}
示例4: addPosting
func addPosting(b *flatbuffers.Builder, p types.Posting) flatbuffers.UOffsetT {
so := b.CreateByteString(p.Source()) // Do this before posting start.
var bo flatbuffers.UOffsetT
if p.ValueLength() > 0 {
bo = b.CreateByteVector(p.ValueBytes())
}
types.PostingStart(b)
types.PostingAddUid(b, p.Uid())
if bo > 0 {
types.PostingAddValue(b, bo)
}
types.PostingAddSource(b, so)
types.PostingAddTs(b, p.Ts())
types.PostingAddOp(b, p.Op())
return types.PostingEnd(b)
}
示例5: Value
func (l *List) Value() (result []byte, rerr error) {
l.wg.Wait()
l.RLock()
defer l.RUnlock()
if l.length() == 0 {
return result, fmt.Errorf("No value found")
}
var p types.Posting
if ok := l.get(&p, l.length()-1); !ok {
return result, fmt.Errorf("Unable to get last posting")
}
if p.Uid() != math.MaxUint64 {
return result, fmt.Errorf("No value found")
}
return p.ValueBytes(), nil
}
示例6: TestAddMutation_Value
func TestAddMutation_Value(t *testing.T) {
// logrus.SetLevel(logrus.DebugLevel)
glog.Debug("Running init...")
ol := NewList()
key := Key(10, "value")
dir, err := ioutil.TempDir("", "storetest_")
if err != nil {
t.Error(err)
return
}
defer os.RemoveAll(dir)
ps := new(store.Store)
ps.Init(dir)
clog := commit.NewLogger(dir, "mutations", 50<<20)
clog.Init()
defer clog.Close()
ol.init(key, ps, clog)
glog.Debug("Init successful.")
edge := x.DirectedEdge{
Value: "oh hey there",
Source: "new-testing",
Timestamp: time.Now(),
}
if err := ol.AddMutation(edge, Set); err != nil {
t.Error(err)
}
var p types.Posting
ol.Get(&p, 0)
if p.Uid() != math.MaxUint64 {
t.Errorf("All value uids should go to MaxUint64. Got: %v", p.Uid())
}
var iout interface{}
if err := ParseValue(&iout, p.ValueBytes()); err != nil {
t.Error(err)
}
out := iout.(string)
if out != "oh hey there" {
t.Errorf("Expected a value. Got: [%q]", out)
}
// Run the same check after committing.
if _, err := ol.MergeIfDirty(); err != nil {
t.Error(err)
}
{
var tp types.Posting
if ok := ol.Get(&tp, 0); !ok {
t.Error("While retrieving posting")
}
if err := ParseValue(&iout, tp.ValueBytes()); err != nil {
t.Error(err)
}
out := iout.(string)
if out != "oh hey there" {
t.Errorf("Expected a value. Got: [%q]", out)
}
}
// The value made it to the posting list. Changing it now.
edge.Value = 119
if err := ol.AddMutation(edge, Set); err != nil {
t.Error(err)
}
if ol.Length() != 1 {
t.Errorf("Length should be one. Got: %v", ol.Length())
}
if ok := ol.Get(&p, 0); !ok {
t.Error("While retrieving posting")
}
if err := ParseValue(&iout, p.ValueBytes()); err != nil {
t.Error(err)
}
intout := iout.(float64)
if intout != 119 {
t.Errorf("Expected 119. Got: %v", intout)
}
}