mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-02-24 23:53:12 +00:00
Base bytes on bytePairs.
This commit is contained in:
parent
b98d0bca9c
commit
8c7290c0fe
@ -2,16 +2,9 @@ from asyncdispatch import Port
|
||||
|
||||
proc `$`*(port: Port): string = $int(port)
|
||||
|
||||
# REVIEW: you can base one of the iterators on the other to avoid the code duplication
|
||||
# e.g. implement `bytes` in terms of `bytePairs`.
|
||||
iterator bytes*[T: SomeUnsignedInt](value: T): byte {.inline.} =
|
||||
## Traverse the bytes of a value in little endian
|
||||
let argSize = sizeOf(T)
|
||||
for bIdx in 0 ..< argSize:
|
||||
let
|
||||
shift = bIdx.uint * 8
|
||||
mask = 0xff'u64 shl shift
|
||||
yield byte((value and mask) shr shift)
|
||||
yield value.bytePairs[1]
|
||||
|
||||
iterator bytePairs*[T: SomeUnsignedInt](value: T): tuple[key: int, val: byte] {.inline.} =
|
||||
let argSize = sizeOf(T)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user