本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.BinaryMarshallable.UnmarshalBinaryData方法的典型用法代碼示例。如果您正苦於以下問題:Golang BinaryMarshallable.UnmarshalBinaryData方法的具體用法?Golang BinaryMarshallable.UnmarshalBinaryData怎麽用?Golang BinaryMarshallable.UnmarshalBinaryData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/factomd/common/interfaces.BinaryMarshallable
的用法示例。
在下文中一共展示了BinaryMarshallable.UnmarshalBinaryData方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Unmarshall
// Make this stuff easier to read.
func Unmarshall(thing interfaces.BinaryMarshallable, err error, data []byte) ([]byte, error) {
if err != nil {
return nil, err
}
newdata, err := thing.UnmarshalBinaryData(data)
return newdata, err
}
示例2: Get
func (db *BoltDB) Get(bucket []byte, key []byte, destination interfaces.BinaryMarshallable) (interfaces.BinaryMarshallable, error) {
db.Sem.RLock()
defer db.Sem.RUnlock()
var v []byte
db.db.View(func(tx *bolt.Tx) error {
b := tx.Bucket(bucket)
if b == nil {
return nil
}
v = b.Get(key)
if v == nil {
return nil
}
return nil
})
if v == nil { // If the value is undefined, return nil
return nil, nil
}
_, err := destination.UnmarshalBinaryData(v)
if err != nil {
return nil, err
}
return destination, nil
}
示例3: Get
func (db *MapDB) Get(bucket, key []byte, destination interfaces.BinaryMarshallable) (interfaces.BinaryMarshallable, error) {
db.createCache(bucket)
db.Sem.RLock()
defer db.Sem.RUnlock()
if db.Cache == nil {
db.Cache = map[string]map[string][]byte{}
}
_, ok := db.Cache[string(bucket)]
if ok == false {
db.Cache[string(bucket)] = map[string][]byte{}
}
v, ok := db.Cache[string(bucket)][string(key)]
if ok == false {
return nil, nil
}
if v == nil {
return nil, nil
}
_, err := destination.UnmarshalBinaryData(v)
if err != nil {
return nil, err
}
return destination, nil
}
示例4: TestCommitMarshalUnmarshal
func TestCommitMarshalUnmarshal(t *testing.T) {
blocks := testHelper.CreateFullTestBlockSet()
for _, block := range blocks {
for _, tx := range block.ECBlock.GetEntries() {
h1, err := tx.MarshalBinary()
if err != nil {
t.Errorf("Error marshalling - %v", err)
}
var h2 []byte
var e interfaces.BinaryMarshallable
switch tx.ECID() {
case ECIDChainCommit:
e = new(CommitChain)
break
case ECIDEntryCommit:
e = new(CommitEntry)
break
case ECIDBalanceIncrease:
e = new(IncreaseBalance)
break
case ECIDMinuteNumber:
e = new(MinuteNumber)
break
case ECIDServerIndexNumber:
e = new(ServerIndexNumber)
break
default:
t.Error("Wrong ECID")
break
}
h2, err = e.UnmarshalBinaryData(h1)
if err != nil {
t.Logf("Tried to unmarshal %x", h1)
t.Errorf("Error unmarshalling - %v", err)
continue
}
if len(h2) > 0 {
t.Errorf("Leftovers from unmarshalling - %x", h2)
}
h2, err = e.MarshalBinary()
if err != nil {
t.Errorf("Error marshalling2 - %v", err)
continue
}
if primitives.AreBytesEqual(h1, h2) == false {
t.Error("ECEntries are not identical - %x vs %x", h1, h2)
}
}
}
}
示例5: Get
func (db *LevelDB) Get(bucket []byte, key []byte, destination interfaces.BinaryMarshallable) (interfaces.BinaryMarshallable, error) {
db.dbLock.Lock()
defer db.dbLock.Unlock()
ldbKey := append(bucket, key...)
data, err := db.lDB.Get(ldbKey, db.ro)
if err != nil {
if strings.Contains(err.Error(), "not found") {
return nil, nil
}
return nil, err
}
_, err = destination.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
return destination, nil
}