mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 18:13:54 +08:00
feat(bitswap:msg) impl FromSwarm method
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
package bitswap
|
package bitswap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
|
||||||
|
|
||||||
blocks "github.com/jbenet/go-ipfs/blocks"
|
blocks "github.com/jbenet/go-ipfs/blocks"
|
||||||
nm "github.com/jbenet/go-ipfs/net/message"
|
nm "github.com/jbenet/go-ipfs/net/message"
|
||||||
swarm "github.com/jbenet/go-ipfs/net/swarm"
|
swarm "github.com/jbenet/go-ipfs/net/swarm"
|
||||||
@ -41,6 +43,15 @@ func (m *message) AppendBlock(b *blocks.Block) {
|
|||||||
m.pb.Blocks = append(m.pb.Blocks, b.Data)
|
m.pb.Blocks = append(m.pb.Blocks, b.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FromSwarm(sms swarm.Message) (BitSwapMessage, error) {
|
||||||
|
var protoMsg PBMessage
|
||||||
|
err := proto.Unmarshal(sms.Data, &protoMsg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return newMessageFromProto(protoMsg), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *message) ToProto() *PBMessage {
|
func (m *message) ToProto() *PBMessage {
|
||||||
cp := m.pb
|
cp := m.pb
|
||||||
return &cp
|
return &cp
|
||||||
|
Reference in New Issue
Block a user