mirror of
https://github.com/status-im/nim-rlp.git
synced 2025-02-10 13:06:27 +00:00
handle char arrays as blobs just like byte arrays
This commit is contained in:
parent
8acf725628
commit
a97cb6c32f
4
rlp.nim
4
rlp.nim
@ -278,7 +278,7 @@ proc read*(rlp: var Rlp, T: typedesc[enum]): T =
|
||||
proc read*[R, E](rlp: var Rlp, T: type array[R, E]): T =
|
||||
mixin read
|
||||
|
||||
when E is byte:
|
||||
when E is (byte or char):
|
||||
if not rlp.isBlob:
|
||||
raise newException(BadCastError, "The source RLP is not a blob.")
|
||||
|
||||
@ -302,7 +302,7 @@ proc read*[R, E](rlp: var Rlp, T: type array[R, E]): T =
|
||||
proc read*[E](rlp: var Rlp, T: type seq[E]): T =
|
||||
mixin read
|
||||
|
||||
when E is byte:
|
||||
when E is (byte or char):
|
||||
var bytes = rlp.toBytes
|
||||
result = newSeq[byte](bytes.len)
|
||||
copyMem(addr result[0], bytes.baseAddr, bytes.len)
|
||||
|
@ -148,6 +148,9 @@ proc append*(self; data: string) =
|
||||
proc appendBlob(self; data: openarray[byte]) =
|
||||
appendImpl(self, data, BLOB_START_MARKER)
|
||||
|
||||
proc appendBlob(self; data: openarray[char]) =
|
||||
appendImpl(self, data, BLOB_START_MARKER)
|
||||
|
||||
proc appendBytesRange(self; data: BytesRange) =
|
||||
appendImpl(self, data, BLOB_START_MARKER)
|
||||
|
||||
@ -176,7 +179,7 @@ proc append*[T](self; listOrBlob: openarray[T]) =
|
||||
|
||||
# TODO: This append proc should be overloaded by `openarray[byte]` after
|
||||
# nim bug #7416 is fixed.
|
||||
when T is byte:
|
||||
when T is (byte or char):
|
||||
self.appendBlob(listOrBlob)
|
||||
else:
|
||||
self.startList listOrBlob.len
|
||||
|
Loading…
x
Reference in New Issue
Block a user