本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.BinaryMarshallable.MarshalBinary方法的典型用法代碼示例。如果您正苦於以下問題:Golang BinaryMarshallable.MarshalBinary方法的具體用法?Golang BinaryMarshallable.MarshalBinary怎麽用?Golang BinaryMarshallable.MarshalBinary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/factomd/common/interfaces.BinaryMarshallable
的用法示例。
在下文中一共展示了BinaryMarshallable.MarshalBinary方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
}
}
示例2: Put
func (d *BoltDB) Put(bucket []byte, key []byte, data interfaces.BinaryMarshallable) error {
hex, err := data.MarshalBinary()
if err != nil {
return err
}
err = d.db.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucketIfNotExists(bucket)
if err != nil {
return err
}
b := tx.Bucket(bucket)
err = b.Put(key, hex)
return err
})
return err
}
示例3: rawPut
func (db *MapDB) rawPut(bucket, key []byte, data interfaces.BinaryMarshallable) error {
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{}
}
var hex []byte
var err error
if data != nil {
hex, err = data.MarshalBinary()
if err != nil {
return err
}
}
db.Cache[string(bucket)][string(key)] = hex
return nil
}
示例4: Put
func (db *LevelDB) Put(bucket []byte, key []byte, data interfaces.BinaryMarshallable) error {
if db.lbatch == nil {
db.lbatch = new(leveldb.Batch)
}
defer db.lbatch.Reset()
ldbKey := append(bucket, key...)
hex, err := data.MarshalBinary()
if err != nil {
return err
}
db.lbatch.Put(ldbKey, hex)
err = db.lDB.Write(db.lbatch, db.wo)
if err != nil {
return err
}
return nil
}
示例5: AreBinaryMarshallablesEqual
func AreBinaryMarshallablesEqual(b1, b2 interfaces.BinaryMarshallable) (bool, error) {
if b1 == nil {
if b2 == nil {
return true, nil
}
return false, nil
}
if b2 == nil {
return false, nil
}
bytes1, err := b1.MarshalBinary()
if err != nil {
return false, err
}
bytes2, err := b2.MarshalBinary()
if err != nil {
return false, err
}
return AreBytesEqual(bytes1, bytes2), nil
}
示例6: HandleV2RawData
func HandleV2RawData(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
hashkey := new(HashRequest)
err := MapToObject(params, hashkey)
if err != nil {
panic(reflect.TypeOf(params))
return nil, NewInvalidParamsError()
}
h, err := primitives.HexToHash(hashkey.Hash)
if err != nil {
return nil, NewInvalidHashError()
}
var block interfaces.BinaryMarshallable
var b []byte
if block, _ = state.FetchECTransactionByHash(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ = state.FetchFactoidTransactionByHash(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ = state.FetchEntryByHash(h); block != nil {
b, _ = block.MarshalBinary()
}
if b == nil {
dbase := state.GetAndLockDB()
defer state.UnlockDB()
// try to find the block data in db and return the first one found
if block, _ = dbase.FetchFBlock(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ = dbase.FetchDBlock(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ = dbase.FetchABlock(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ = dbase.FetchEBlock(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ = dbase.FetchECBlock(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ = dbase.FetchFBlock(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ = dbase.FetchEntry(h); block != nil {
b, _ = block.MarshalBinary()
} else {
return nil, NewEntryNotFoundError()
}
}
d := new(RawDataResponse)
d.Data = hex.EncodeToString(b)
return d, nil
}
示例7: MarshalSign
// Sign signs msg with PrivateKey and return Signature
func (pk *PrivateKey) MarshalSign(msg interfaces.BinaryMarshallable) (sig interfaces.IFullSignature) {
data, _ := msg.MarshalBinary()
return pk.Sign(data)
}