mirror of https://github.com/status-im/nim-eth.git
RLP serialization routines for types used in the ETH2 spec
This commit is contained in:
parent
f8da72ca96
commit
f0315b0988
|
@ -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
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue