diff options
| author | Oskari Timperi <oswjk@users.noreply.github.com> | 2019-06-25 22:59:33 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-25 22:59:33 +0300 |
| commit | 9df08c3c052ff4a2ee880496527864be6b9e8f1a (patch) | |
| tree | da3a6e491cef1385fdaeba45e1cab4867072096a | |
| parent | 32a6de11389aca631435f78aa5be0857053a8a9d (diff) | |
| parent | e84696876a2dade770a99b65c0a6c7076a48b3e4 (diff) | |
| download | nimpb-9df08c3c052ff4a2ee880496527864be6b9e8f1a.tar.gz nimpb-9df08c3c052ff4a2ee880496527864be6b9e8f1a.zip | |
Merge pull request #13 from xcokazaki/fix-type-check-on-nim-0.20
Update nim 0.20
| -rw-r--r-- | nimpb/nimpb.nim | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/nimpb/nimpb.nim b/nimpb/nimpb.nim index 9933b18..9691650 100644 --- a/nimpb/nimpb.nim +++ b/nimpb/nimpb.nim @@ -118,7 +118,7 @@ proc zigzagEncode*(n: int32): uint32 = let x = cast[uint32](n) let a = cast[int32](x shl 1) let b = -cast[int32](x shr 31) - result = uint32(a xor b) + result = cast[uint32](a xor b) proc zigzagDecode*(n: uint32): int32 = ## ZigZag decode a 32-bit unsigned integer. @@ -153,7 +153,7 @@ template fieldNumber*(tag: Tag): int = proc protoReadByte(stream: Stream): byte = ## Read a byte from a stream. - result = readInt8(stream).byte + result = cast[byte](readInt8(stream)) proc protoWriteByte(stream: Stream, b: byte) = ## Write a byte to a stream. @@ -399,8 +399,9 @@ proc protoWriteBytes*(stream: Stream, bytes: seq[byte], fieldNumber: int) = proc safeReadStr*(stream: Stream, size: int): string = result = newString(size) - if readData(stream, addr(result[0]), size) != size: - raise newException(IOError, "cannot read from stream") + if size > 0: + if readData(stream, addr(result[0]), size) != size: + raise newException(IOError, "cannot read from stream") proc protoReadString*(stream: Stream): string = let size = int(protoReadUInt64(stream)) |
