本文整理汇总了Golang中github.com/skycoin/skycoin/src/aether/encoder.DeserializeRaw函数的典型用法代码示例。如果您正苦于以下问题:Golang DeserializeRaw函数的具体用法?Golang DeserializeRaw怎么用?Golang DeserializeRaw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DeserializeRaw函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGivePeersMessage
func TestGivePeersMessage(t *testing.T) {
d := newDefaultDaemon()
defer shutdown(d)
addrs := []string{addr, addrb, "7"}
peers := make([]*pex.Peer, 3)
for i, addr := range addrs {
peers[i] = &pex.Peer{Addr: addr}
}
m := NewGivePeersMessage(peers)
assert.Equal(t, len(m.GetPeers()), 2)
testSimpleMessageHandler(t, d, m)
assert.Equal(t, m.GetPeers()[0], addrs[0])
assert.Equal(t, m.GetPeers()[1], addrs[1])
// Test disabled
d.Peers.Config.Disabled = true
m.Process(d)
assert.Equal(t, len(d.Peers.Peers.Peerlist), 0)
// Test serialization
m = NewGivePeersMessage(peers)
b := encoder.Serialize(m)
m2 := GivePeersMessage{}
assert.Nil(t, encoder.DeserializeRaw(b, &m2))
assert.Equal(t, *m, m2)
// Peers should be added to the pex when processed
d.Peers.Config.Disabled = false
m.Process(d)
assert.Equal(t, len(d.Peers.Peers.Peerlist), 2)
gnet.EraseMessages()
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:32,代码来源:messages_test.go
示例2: TransactionDeserialize
func TransactionDeserialize(b []byte) Transaction {
t := Transaction{}
if err := encoder.DeserializeRaw(b, &t); err != nil {
log.Panic("Failed to deserialize transaction")
}
return t
}
开发者ID:keepwalking1234,项目名称:skycoin,代码行数:7,代码来源:transactions.go
示例3: TestPingMessage
func TestPingMessage(t *testing.T) {
d := newDefaultDaemon()
defer shutdown(d)
p := d.Pool.Pool
m := &PingMessage{}
testSimpleMessageHandler(t, d, m)
m.c = messageContext(addr)
go p.ConnectionWriteLoop(m.c.Conn)
defer m.c.Conn.Close()
assert.NotPanics(t, func() { m.Process(d) })
// A pong message should have been sent
wait()
assert.Equal(t, len(p.SendResults), 1)
if len(p.SendResults) == 0 {
t.Fatalf("SendResults empty, would block")
}
sr := <-p.SendResults
assert.Equal(t, sr.Connection, m.c.Conn)
assert.Nil(t, sr.Error)
_, ok := sr.Message.(*PongMessage)
assert.True(t, ok)
assert.False(t, m.c.Conn.LastSent.IsZero())
// Test serialization
mm := PingMessage{}
b := encoder.Serialize(mm)
m2 := PingMessage{}
assert.Nil(t, encoder.DeserializeRaw(b, &m2))
assert.Equal(t, mm, m2)
gnet.EraseMessages()
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:33,代码来源:messages_test.go
示例4: Dec_block
//decode block to bytes
func Dec_block(b []byte) (SignedBlock, error) {
if len(b) < 16 {
log.Panic()
}
var dln uint64 = le_Uint64(b[0:8])
var seq uint64 = le_Uint64(b[8:16])
var chk uint64 = le_Uint64(b[16:24])
if dln != uint64(len(b)) {
log.Panic("Dec_block, length check failed")
}
b = b[24:] //cleave off header
if chk != FnvsHash(b) {
log.Panic("Dec_block, checksum failed")
}
var sb SignedBlock
err := encoder.DeserializeRaw(b, &sb)
if err != nil {
log.Panic("Dec_block, deserialization failed")
}
if seq != sb.Block.Head.BkSeq {
log.Panic("Dec_block, seq mismatch")
}
return sb, nil
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:32,代码来源:blockchain_file.go
示例5: TestGetPeersMessage
func TestGetPeersMessage(t *testing.T) {
d := newDefaultDaemon()
defer shutdown(d)
p := d.Pool
m := NewGetPeersMessage()
testSimpleMessageHandler(t, d, m)
d.Peers.Peers.AddPeer(addr)
q, err := d.Peers.Peers.AddPeer(addrb)
assert.Nil(t, err)
q.Private = true
d.Peers.Config.ReplyCount = 100
m.c = messageContext(addr)
// Peers disabled
d.Peers.Config.Disabled = true
assert.NotPanics(t, func() { m.Process(d) })
wait()
assert.Equal(t, len(p.Pool.SendResults), 0)
assert.True(t, m.c.Conn.LastSent.IsZero())
// Peers enabled
d.Peers.Config.Disabled = false
m.c = messageContext(addr)
defer m.c.Conn.Close()
go p.Pool.ConnectionWriteLoop(m.c.Conn)
assert.NotPanics(t, func() { m.Process(d) })
wait()
assert.Equal(t, len(p.Pool.SendResults), 1)
if len(p.Pool.SendResults) == 0 {
t.Fatal("SendResults empty, would block")
}
sr := <-p.Pool.SendResults
assert.Nil(t, sr.Error)
assert.Equal(t, sr.Connection, m.c.Conn)
msg, ok := sr.Message.(*GivePeersMessage)
assert.True(t, ok)
// Private peer should not be included
ipAddr, err := NewIPAddr(addr)
assert.Nil(t, err)
assert.Equal(t, msg.Peers, []IPAddr{ipAddr})
assert.False(t, m.c.Conn.LastSent.IsZero())
// If no peers, nothing should happen
m.c.Conn.LastSent = util.ZeroTime()
delete(d.Peers.Peers.Peerlist, addr)
assert.NotPanics(t, func() { m.Process(d) })
wait()
assert.Equal(t, len(p.Pool.SendResults), 0)
assert.True(t, m.c.Conn.LastSent.IsZero())
// Test serialization
m = NewGetPeersMessage()
b := encoder.Serialize(m)
m2 := GetPeersMessage{}
assert.Nil(t, encoder.DeserializeRaw(b, &m2))
assert.Equal(t, *m, m2)
gnet.EraseMessages()
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:59,代码来源:messages_test.go
示例6: getBlock
func (bt *BlockTree) getBlock(hash cipher.SHA256) *coin.Block {
bin := bt.blocks.Get(hash[:])
if bin == nil {
return nil
}
block := coin.Block{}
if err := encoder.DeserializeRaw(bin, &block); err != nil {
return nil
}
return &block
}
开发者ID:skycoin,项目名称:skycoin,代码行数:11,代码来源:block_tree.go
示例7: getBucketValue
func getBucketValue(db *bolt.DB, name []byte, key []byte, value interface{}) error {
return db.View(func(tx *bolt.Tx) error {
b := tx.Bucket(name)
bin := b.Get(key)
if bin == nil {
value = nil
return nil
}
return encoder.DeserializeRaw(bin, value)
})
}
开发者ID:skycoin,项目名称:skycoin,代码行数:11,代码来源:historydb_test.go
示例8: Get
// Get returns signature of specific block
func (bs BlockSigs) Get(hash cipher.SHA256) (cipher.Sig, error) {
bin := bs.Sigs.Get(hash[:])
if bin == nil {
return cipher.Sig{}, fmt.Errorf("no sig for %v", hash.Hex())
}
var sig cipher.Sig
if err := encoder.DeserializeRaw(bin, &sig); err != nil {
return cipher.Sig{}, err
}
return sig, nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:12,代码来源:blocksigs.go
示例9: Get
// Get return nil on not found.
func (au *addressUx) Get(address cipher.Address) ([]cipher.SHA256, error) {
uxHashes := []cipher.SHA256{}
bin := au.bkt.Get(address.Bytes())
if bin == nil {
return nil, nil
}
if err := encoder.DeserializeRaw(bin, &uxHashes); err != nil {
return nil, err
}
return uxHashes, nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:12,代码来源:address.go
示例10: getHashInDepth
func (bt *BlockTree) getHashInDepth(depth uint64, filter func(ps []coin.HashPair) cipher.SHA256) (cipher.SHA256, error) {
key := itob(depth)
pairsBin := bt.tree.Get(key)
pairs := []coin.HashPair{}
if err := encoder.DeserializeRaw(pairsBin, &pairs); err != nil {
return cipher.SHA256{}, err
}
hash := filter(pairs)
return hash, nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:11,代码来源:block_tree.go
示例11: LoadSerializedBlockchain
func LoadSerializedBlockchain(filename string) (*SerializedBlockchain, error) {
sbc := &SerializedBlockchain{}
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
err = encoder.DeserializeRaw(data, sbc)
if err != nil {
return nil, err
}
return sbc, nil
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:12,代码来源:serialization.go
示例12: TestIntroductionMessageHandle
func TestIntroductionMessageHandle(t *testing.T) {
d := newDefaultDaemon()
defer shutdown(d)
mc := messageContext(addr)
m := NewIntroductionMessage(d.Messages.Mirror, d.Config.Version,
d.Pool.Pool.Config.Port)
// Test valid handling
m.Mirror = d.Messages.Mirror + 1
err := m.Handle(mc, d)
assert.Nil(t, err)
if len(d.messageEvents) == 0 {
t.Fatalf("messageEvent is empty")
}
<-d.messageEvents
assert.True(t, m.valid)
m.valid = false
// Test matching mirror
m.Mirror = d.Messages.Mirror
err = m.Handle(mc, d)
assert.Equal(t, err, DisconnectSelf)
m.Mirror = d.Messages.Mirror + 1
assert.False(t, m.valid)
// Test mismatched d.Config.Version
m.Version = d.Config.Version + 1
err = m.Handle(mc, d)
assert.Equal(t, err, DisconnectInvalidVersion)
assert.False(t, m.valid)
// Test serialization
m = NewIntroductionMessage(d.Messages.Mirror, d.Config.Version,
d.Pool.Pool.Config.Port)
b := encoder.Serialize(m)
m2 := IntroductionMessage{}
assert.Nil(t, encoder.DeserializeRaw(b, &m2))
assert.Equal(t, *m, m2)
// Test already connected
d.mirrorConnections[m.Mirror] = make(map[string]uint16)
d.mirrorConnections[m.Mirror][addrIP] = addrPort + 1
err = m.Handle(mc, d)
assert.Equal(t, err, DisconnectConnectedTwice)
delete(d.mirrorConnections, m.Mirror)
assert.False(t, m.valid)
for len(d.messageEvents) > 0 {
<-d.messageEvents
}
gnet.EraseMessages()
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:52,代码来源:messages_test.go
示例13: GetAllBlockHashInDepth
// GetAllBlockHashInDepth returns all block hash of N depth in the tree.
func (bt *BlockTree) GetAllBlockHashInDepth(depth uint64) ([]cipher.SHA256, error) {
key := itob(depth)
pairsBin := bt.tree.Get(key)
pairs := []coin.HashPair{}
if err := encoder.DeserializeRaw(pairsBin, &pairs); err != nil {
return []cipher.SHA256{}, err
}
hashes := make([]cipher.SHA256, len(pairs))
for i, hp := range pairs {
hashes[i] = hp.Hash
}
return hashes, nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:14,代码来源:block_tree.go
示例14: TestGetBlocksMessageHandle
func TestGetBlocksMessageHandle(t *testing.T) {
d := newDefaultDaemon()
defer shutdown(d)
m := NewGetBlocksMessage(uint64(1))
assert.Equal(t, m.LastBlock, uint64(1))
testSimpleMessageHandler(t, d, m)
// Test serialization
m = NewGetBlocksMessage(uint64(106))
b := encoder.Serialize(m)
m2 := GetBlocksMessage{}
assert.Nil(t, encoder.DeserializeRaw(b, &m2))
assert.Equal(t, *m, m2)
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:14,代码来源:visor_test.go
示例15: Get
// Get get transaction by tx hash, return nil on not found.
func (txs transactions) Get(hash cipher.SHA256) (*Transaction, error) {
bin := txs.bkt.Get(hash[:])
if bin == nil {
return nil, nil
}
// deserialize tx
var tx Transaction
if err := encoder.DeserializeRaw(bin, &tx); err != nil {
return nil, err
}
return &tx, nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:15,代码来源:transaction.go
示例16: TestPongMessage
func TestPongMessage(t *testing.T) {
cmsgs := NewMessagesConfig()
cmsgs.Register()
m := &PongMessage{}
// Pongs dont do anything
assert.Nil(t, m.Handle(messageContext(addr), nil))
gnet.EraseMessages()
// Test serialization
mm := PongMessage{}
b := encoder.Serialize(mm)
m2 := PongMessage{}
assert.Nil(t, encoder.DeserializeRaw(b, &m2))
assert.Equal(t, mm, m2)
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:16,代码来源:messages_test.go
示例17: getHashPairInDepth
func getHashPairInDepth(tree *bolt.Bucket, dep uint64, fn func(hp coin.HashPair) bool) ([]coin.HashPair, error) {
v := tree.Get(itob(dep))
if v == nil {
return []coin.HashPair{}, nil
}
hps := []coin.HashPair{}
if err := encoder.DeserializeRaw(v, &hps); err != nil {
return nil, err
}
pairs := []coin.HashPair{}
for _, ps := range hps {
if fn(ps) {
pairs = append(pairs, ps)
}
}
return pairs, nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:18,代码来源:block_tree.go
示例18: TestGiveBlocksMessageHandle
func TestGiveBlocksMessageHandle(t *testing.T) {
d := newDefaultDaemon()
defer shutdown(d)
_, mv := setupVisor()
blocks := []visor.SignedBlock{mv.GetGenesisBlock()}
m := NewGiveBlocksMessage(blocks)
assert.Equal(t, m.Blocks, blocks)
testSimpleMessageHandler(t, d, m)
// Test serialization
bks, err := makeBlocks(mv, 4)
assert.Nil(t, err)
blocks = append(blocks, bks...)
m = NewGiveBlocksMessage(blocks)
b := encoder.Serialize(m)
m2 := GiveBlocksMessage{}
assert.Nil(t, encoder.DeserializeRaw(b, &m2))
assert.Equal(t, *m, m2)
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:19,代码来源:visor_test.go
示例19: LoadBlockSigs
func LoadBlockSigs(filename string) (BlockSigs, error) {
bs := NewBlockSigs()
data, err := ioutil.ReadFile(filename)
if err != nil {
return bs, err
}
sigs := BlockSigsSerialized{make([]BlockSigSerialized, 0)}
err = encoder.DeserializeRaw(data, &sigs)
if err != nil {
return bs, err
}
bs.Sigs = make(map[uint64]cipher.Sig, len(sigs.Sigs))
for _, s := range sigs.Sigs {
bs.Sigs[s.BkSeq] = s.Sig
if s.BkSeq > bs.MaxSeq {
bs.MaxSeq = s.BkSeq
}
}
return bs, nil
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:20,代码来源:blocksigs.go
示例20: TestAnnounceTxnsMessageHandle
func TestAnnounceTxnsMessageHandle(t *testing.T) {
d := newDefaultDaemon()
defer shutdown(d)
tx := createUnconfirmedTxn()
txns := []cipher.SHA256{tx.Txn.Hash()}
m := NewAnnounceTxnsMessage(txns)
assert.Equal(t, m.Txns, txns)
testSimpleMessageHandler(t, d, m)
// Test serialization
tx = createUnconfirmedTxn()
txns = append(txns, tx.Txn.Hash())
tx = createUnconfirmedTxn()
txns = append(txns, tx.Txn.Hash())
m = NewAnnounceTxnsMessage(txns)
assert.Equal(t, len(m.Txns), 3)
b := encoder.Serialize(m)
m2 := AnnounceTxnsMessage{}
assert.Nil(t, encoder.DeserializeRaw(b, &m2))
assert.Equal(t, *m, m2)
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:21,代码来源:visor_test.go
注:本文中的github.com/skycoin/skycoin/src/aether/encoder.DeserializeRaw函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论