Skip to content

Commit

Permalink
RLP serialization routines for types used in the ETH2 spec
Browse files Browse the repository at this point in the history
  • Loading branch information
zah committed Aug 15, 2019
1 parent f8da72c commit f0315b0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions eth/rlp/bitseqs.nim
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions eth/rlp/options.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f0315b0

Please sign in to comment.