mirror of https://github.com/status-im/nim-rlp.git
Workaround enum serialization
This commit is contained in:
parent
e47708b0bd
commit
078aa161dd
2
rlp.nim
2
rlp.nim
|
@ -276,7 +276,7 @@ proc read*(rlp: var Rlp, T: type Integer): Integer =
|
|||
rlp.skipElem
|
||||
|
||||
proc read*(rlp: var Rlp, T: typedesc[enum]): T =
|
||||
result = T(rlp.toInt(int))
|
||||
result = type(result)(rlp.toInt(int))
|
||||
rlp.skipElem
|
||||
|
||||
proc read*[R, E](rlp: var Rlp, T: type array[R, E]): T =
|
||||
|
|
|
@ -33,13 +33,20 @@ test "you cannot finish a list without appending enough elements":
|
|||
proc withNewLines(x: string): string = x & "\n"
|
||||
|
||||
test "encode/decode object":
|
||||
type MyObj = object
|
||||
a: array[3, char]
|
||||
b: int
|
||||
type
|
||||
MyEnum = enum
|
||||
foo,
|
||||
bar
|
||||
|
||||
MyObj = object
|
||||
a: array[3, char]
|
||||
b: int
|
||||
c: MyEnum
|
||||
|
||||
var input: MyObj
|
||||
input.a = ['e', 't', 'h']
|
||||
input.b = 63
|
||||
input.c = bar
|
||||
|
||||
var writer = initRlpWriter()
|
||||
writer.append(input)
|
||||
|
|
Loading…
Reference in New Issue