RLP serialization routines for types used in the ETH2 spec

This commit is contained in:
Zahary Karadjov 2019-08-15 17:44:16 +02:00
parent f8da72ca96
commit f0315b0988
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 31 additions and 0 deletions

14
eth/rlp/bitseqs.nim Normal file
View File

@ -0,0 +1,14 @@
import
stew/bitseqs, ../rlp
type
Bytes = seq[byte]
proc read*(rlp: var Rlp, T: type BitSeq): T {.inline.} =
T read(rlp, Bytes)
proc append*(writer: var RlpWriter, value: BitSeq) =
append(writer, Bytes(value))
export
bitseqs, rlp

17
eth/rlp/options.nim Normal file
View File

@ -0,0 +1,17 @@
import
std/options, ../rlp
proc read*[T](rlp: var Rlp, O: type Option[T]): O {.inline.} =
mixin read
if not rlp.isEmpty:
result = some read(rlp, T)
proc append*(writer: var RlpWriter, value: Option) =
if value.isSome:
writer.append value.get
else:
writer.append ""
export
options, rlp