mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-11 09:53:12 +00:00
19 lines
460 B
Nim
19 lines
460 B
Nim
import std/strformat
|
|
|
|
import pkg/stew/byteutils
|
|
|
|
func bencode*(value: uint64): seq[byte] =
|
|
fmt"i{value}e".toBytes
|
|
|
|
func bencode*(value: int64): seq[byte] =
|
|
fmt"i{value}e".toBytes
|
|
|
|
func bencode*(value: openArray[byte]): seq[byte] =
|
|
fmt"{value.len}:".toBytes & @value
|
|
|
|
func bencode*(value: string): seq[byte] =
|
|
bencode(value.toBytes)
|
|
|
|
proc bencode*[T: not byte](value: openArray[T]): seq[byte] =
|
|
fmt"l{value.mapIt(bencode(it).toString).join}e".toBytes
|