mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-03-03 05:50:40 +00:00
* abort download if atleast one block failed * make chunker a regular object * updating questionable * updating vendor deps * cleanup unused imports * Remove mention of Waku
18 lines
427 B
Nim
18 lines
427 B
Nim
import pkg/libp2p/varint
|
|
|
|
import ./helpers/nodeutils
|
|
import ./helpers/randomchunker
|
|
|
|
export randomchunker, nodeutils
|
|
|
|
proc lenPrefix*(msg: openArray[byte]): seq[byte] =
|
|
## Write `msg` with a varint-encoded length prefix
|
|
##
|
|
|
|
let vbytes = PB.toBytes(msg.len().uint64)
|
|
var buf = newSeqUninitialized[byte](msg.len() + vbytes.len)
|
|
buf[0..<vbytes.len] = vbytes.toOpenArray()
|
|
buf[vbytes.len..<buf.len] = msg
|
|
|
|
return buf
|