mirror of https://github.com/status-im/nim-rlp.git
rlp.read for openarrays
This commit is contained in:
parent
09718bb5c3
commit
8acf725628
9
rlp.nim
9
rlp.nim
|
@ -276,6 +276,8 @@ proc read*(rlp: var Rlp, T: typedesc[enum]): T =
|
|||
rlp.skipElem
|
||||
|
||||
proc read*[R, E](rlp: var Rlp, T: type array[R, E]): T =
|
||||
mixin read
|
||||
|
||||
when E is byte:
|
||||
if not rlp.isBlob:
|
||||
raise newException(BadCastError, "The source RLP is not a blob.")
|
||||
|
@ -297,7 +299,9 @@ proc read*[R, E](rlp: var Rlp, T: type array[R, E]): T =
|
|||
result[i] = rlp.read(E)
|
||||
inc i
|
||||
|
||||
proc read*[E](rlp: var Rlp, T: typedesc[seq[E]]): T =
|
||||
proc read*[E](rlp: var Rlp, T: type seq[E]): T =
|
||||
mixin read
|
||||
|
||||
when E is byte:
|
||||
var bytes = rlp.toBytes
|
||||
result = newSeq[byte](bytes.len)
|
||||
|
@ -311,6 +315,9 @@ proc read*[E](rlp: var Rlp, T: typedesc[seq[E]]): T =
|
|||
for elem in rlp:
|
||||
result.add rlp.read(E)
|
||||
|
||||
proc read*[E](rlp: var Rlp, T: type openarray[E]): seq[E] =
|
||||
result = read(rlp, seq[E])
|
||||
|
||||
proc read*(rlp: var Rlp, T: typedesc[object|tuple],
|
||||
wrappedInList = wrapObjectsInList): T =
|
||||
mixin enumerateRlpFields, read
|
||||
|
|
|
@ -172,6 +172,8 @@ template append*(self; e: enum) =
|
|||
append(self, int(e))
|
||||
|
||||
proc append*[T](self; listOrBlob: openarray[T]) =
|
||||
mixin append
|
||||
|
||||
# TODO: This append proc should be overloaded by `openarray[byte]` after
|
||||
# nim bug #7416 is fixed.
|
||||
when T is byte:
|
||||
|
@ -182,6 +184,8 @@ proc append*[T](self; listOrBlob: openarray[T]) =
|
|||
self.append listOrBlob[i]
|
||||
|
||||
proc append*[T](self; list: seq[T]) =
|
||||
mixin append
|
||||
|
||||
self.startList list.len
|
||||
for i in 0 ..< list.len:
|
||||
self.append list[i]
|
||||
|
|
Loading…
Reference in New Issue