From cc0d45c482728d12eb69fa8c215bdfeff4e2da72 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Tue, 29 Oct 2019 15:38:37 +0200 Subject: [PATCH] Add protoAddress() utility procedure. --- libp2p/multiaddress.nim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libp2p/multiaddress.nim b/libp2p/multiaddress.nim index c9abd49..2e8f6d1 100644 --- a/libp2p/multiaddress.nim +++ b/libp2p/multiaddress.nim @@ -490,6 +490,15 @@ proc protoArgument*(ma: MultiAddress, value: var openarray[byte]): int = if len(value) >= result: copyMem(addr value[0], addr buffer[0], result) +proc protoAddress*(ma: MultiAddress): seq[byte] = + ## Returns MultiAddress ``ma`` protocol address binary blob. + ## + ## If current MultiAddress do not have argument value, then result array will + ## be empty. + result = newSeq[byte](len(ma.data.buffer)) + let res = protoArgument(ma, result) + result.setLen(res) + proc getPart(ma: MultiAddress, index: int): MultiAddress = var header: uint64 var data = newSeq[byte]()