本文整理匯總了Golang中github.com/manishrjain/gocrud/x.Instruction.GobDecode方法的典型用法代碼示例。如果您正苦於以下問題:Golang Instruction.GobDecode方法的具體用法?Golang Instruction.GobDecode怎麽用?Golang Instruction.GobDecode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/manishrjain/gocrud/x.Instruction
的用法示例。
在下文中一共展示了Instruction.GobDecode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExampleInstruction
func ExampleInstruction() {
var i x.Instruction
i.SubjectId = "sid"
i.SubjectType = "stype"
b, err := i.GobEncode()
if err != nil {
panic(err)
}
var o x.Instruction
if err := o.GobDecode(b); err != nil {
panic(err)
}
fmt.Println(o.SubjectId)
fmt.Println(o.SubjectType)
// Output:
// sid
// stype
}
示例2: GetEntity
func (l *Leveldb) GetEntity(_, id string) (result []x.Instruction, rerr error) {
slice := util.BytesPrefix([]byte(id))
iter := l.db.NewIterator(slice, nil)
for iter.Next() {
buf := iter.Value()
if buf == nil {
break
}
var i x.Instruction
if err := i.GobDecode(buf); err != nil {
x.LogErr(log, err).Error("While decoding")
return result, err
}
result = append(result, i)
}
iter.Release()
err := iter.Error()
if err != nil {
x.LogErr(log, err).Error("While iterating")
}
return result, err
}
示例3: Iterate
func (l *Leveldb) Iterate(fromId string, num int,
ch chan x.Entity) (rnum int, rlast x.Entity, rerr error) {
slice := util.Range{Start: []byte(fromId)}
iter := l.db.NewIterator(&slice, nil)
rnum = 0
handled := make(map[x.Entity]bool)
for iter.Next() {
buf := iter.Value()
if buf == nil {
break
}
var i x.Instruction
if err := i.GobDecode(buf); err != nil {
x.LogErr(log, err).Error("While decoding")
return rnum, rlast, err
}
e := x.Entity{Kind: i.SubjectType, Id: i.SubjectId}
rlast = e
if _, present := handled[e]; present {
continue
}
ch <- e
handled[e] = true
rnum += 1
if rnum >= num {
break
}
}
iter.Release()
err := iter.Error()
if err != nil {
x.LogErr(log, err).Error("While iterating")
}
return rnum, rlast, err
}