2018-01-25 21:22:13 +02:00
|
|
|
import macros
|
|
|
|
|
|
|
|
template enumerateRlpFields*[T](x: T, op: untyped) =
|
|
|
|
for f in fields(x): op(f)
|
|
|
|
|
|
|
|
macro rlpFields*(T: typedesc, fields: varargs[untyped]): untyped =
|
|
|
|
var body = newStmtList()
|
|
|
|
let
|
|
|
|
ins = genSym(nskParam, "instance")
|
|
|
|
op = genSym(nskParam, "op")
|
|
|
|
|
|
|
|
for field in fields:
|
|
|
|
body.add quote do: `op`(`ins`.`field`)
|
|
|
|
|
|
|
|
result = quote do:
|
|
|
|
template enumerateRlpFields*(`ins`: `T`, `op`: untyped) {.inject.} =
|
|
|
|
`body`
|
2018-05-18 14:32:06 +03:00
|
|
|
|
|
|
|
template rlpInline* {.pragma.}
|
|
|
|
## This can be specified on a record field in order to avoid the
|
|
|
|
## default behavior of wrapping the record in a RLP list.
|
|
|
|
|