本文整理汇总了Golang中github.com/coreos/etcd/raft/raftpb.Entry.Unmarshal方法的典型用法代码示例。如果您正苦于以下问题:Golang Entry.Unmarshal方法的具体用法?Golang Entry.Unmarshal怎么用?Golang Entry.Unmarshal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/etcd/raft/raftpb.Entry
的用法示例。
在下文中一共展示了Entry.Unmarshal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: mustUnmarshalEntry
func mustUnmarshalEntry(d []byte) raftpb.Entry {
var e raftpb.Entry
if err := e.Unmarshal(d); err != nil {
panic(err)
}
return e
}
示例2: readEntryFrom
func readEntryFrom(r io.Reader, ent *raftpb.Entry) error {
var l uint64
if err := binary.Read(r, binary.BigEndian, &l); err != nil {
return err
}
buf := make([]byte, int(l))
if _, err := io.ReadFull(r, buf); err != nil {
return err
}
return ent.Unmarshal(buf)
}
示例3: readEntry
func (er *entryReader) readEntry(ent *raftpb.Entry) error {
var l uint64
if err := binary.Read(er.r, binary.BigEndian, &l); err != nil {
return err
}
buf := make([]byte, int(l))
if _, err := io.ReadFull(er.r, buf); err != nil {
return err
}
er.bytes.AddBy(8 + int64(l))
return ent.Unmarshal(buf)
}
示例4: Entries
func (w *Wal) Entries(gid uint32, fromTerm, fromIndex uint64) (es []raftpb.Entry, rerr error) {
start := w.entryKey(gid, fromTerm, fromIndex)
prefix := w.prefix(gid)
itr := w.wals.NewIterator()
defer itr.Close()
for itr.Seek(start); itr.ValidForPrefix(prefix); itr.Next() {
data := itr.Value().Data()
var e raftpb.Entry
if err := e.Unmarshal(data); err != nil {
return es, x.Wrapf(err, "While unmarshal raftpb.Entry")
}
es = append(es, e)
}
return
}
示例5: Entries
// Entries implements the raft.Storage interface
func (s *raftStorage) Entries(lo, hi, maxSize uint64) (entries []raftpb.Entry, err error) {
it := s.db.NewIterator(&kv.Range{Start: s.getEntryKey(lo), Limit: s.getEntryKey(hi)})
defer it.Release()
entries = make([]raftpb.Entry, 0)
sizeSoFar := uint64(0)
for ok := it.First(); ok; ok = it.Next() {
var entry raftpb.Entry
err = entry.Unmarshal(it.Value())
if err != nil {
return
}
sizeSoFar += uint64(entry.Size())
// Only stop if we already have at least one entry
if sizeSoFar > maxSize && len(entries) > 0 {
break
}
entries = append(entries, entry)
if sizeSoFar >= maxSize {
break
}
}
err = it.Error()
return
}