mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-01-29 04:40:10 +08:00
peer: Add (*PeerRecord).ToProtoBuf to get protobuf equivalent struct
This commit is contained in:
parent
fdc64dde88
commit
4013be10ed
@ -187,6 +187,19 @@ func (r *PeerRecord) Equal(other *PeerRecord) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// ToProtobuf returns the equivalent Protocol Buffer struct object of a PeerRecord.
|
||||
func (r *PeerRecord) ToProtobuf() (*pb.PeerRecord, error) {
|
||||
idBytes, err := r.PeerID.MarshalBinary()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.PeerRecord{
|
||||
PeerId: idBytes,
|
||||
Addresses: addrsToProtobuf(r.Addrs),
|
||||
Seq: r.Seq,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func addrsFromProtobuf(addrs []*pb.PeerRecord_AddressInfo) []ma.Multiaddr {
|
||||
var out []ma.Multiaddr
|
||||
for _, addr := range addrs {
|
||||
|
Loading…
Reference in New Issue
Block a user