mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-01-13 08:04:28 +00:00
2fb39ca4a3
* use PeerInfo in event handlers * use CidV1 and raw multicodec as default * add block stream abstraction * raises defect * adding dataset abstraction * move blockstream into own dir * reorg files and fix tests * rename dataset to blockset * wip * wip * adding basic test for treehash algo * run blockset tests along with with the rest * remove obsolete contents * fix chunker tests * rename bitswap and move to stores * rename bitwsap to blockexc and move to stores * moare project structure reorg
31 lines
690 B
Nim
31 lines
690 B
Nim
import pkg/libp2p/varint
|
|
|
|
import pkg/dagger/chunker
|
|
import pkg/dagger/blocktype
|
|
import pkg/dagger/blockstream
|
|
|
|
import pkg/questionable
|
|
import pkg/questionable/results
|
|
|
|
export chunker
|
|
|
|
type
|
|
TestStreamProc* = proc(): ?!Block {.raises: [Defect].}
|
|
|
|
TestStream* = ref object of BlockStreamRef
|
|
handler*: TestStreamProc
|
|
|
|
method nextBlock*(b: TestStream): ?!Block =
|
|
b.handler()
|
|
|
|
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
|