-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RLP serialization routines for types used in the ETH2 spec
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|