mirror of
https://github.com/status-im/nim-rlp.git
synced 2025-01-09 13:55:50 +00:00
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
|
rlp.skipElem
|
||||||
|
|
||||||
proc read*(rlp: var Rlp, T: typedesc[enum]): T =
|
proc read*(rlp: var Rlp, T: typedesc[enum]): T =
|
||||||
result = T(rlp.toInt(int))
|
result = type(result)(rlp.toInt(int))
|
||||||
rlp.skipElem
|
rlp.skipElem
|
||||||
|
|
||||||
proc read*[R, E](rlp: var Rlp, T: type array[R, E]): T =
|
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"
|
proc withNewLines(x: string): string = x & "\n"
|
||||||
|
|
||||||
test "encode/decode object":
|
test "encode/decode object":
|
||||||
type MyObj = object
|
type
|
||||||
a: array[3, char]
|
MyEnum = enum
|
||||||
b: int
|
foo,
|
||||||
|
bar
|
||||||
|
|
||||||
|
MyObj = object
|
||||||
|
a: array[3, char]
|
||||||
|
b: int
|
||||||
|
c: MyEnum
|
||||||
|
|
||||||
var input: MyObj
|
var input: MyObj
|
||||||
input.a = ['e', 't', 'h']
|
input.a = ['e', 't', 'h']
|
||||||
input.b = 63
|
input.b = 63
|
||||||
|
input.c = bar
|
||||||
|
|
||||||
var writer = initRlpWriter()
|
var writer = initRlpWriter()
|
||||||
writer.append(input)
|
writer.append(input)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user