From 8c7290c0fe3f6a86c90838798622e615016de6ae Mon Sep 17 00:00:00 2001 From: coffeepots Date: Tue, 15 May 2018 18:16:55 +0100 Subject: [PATCH] Base bytes on bytePairs. --- eth-rpc/server/private/transportutils.nim | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/eth-rpc/server/private/transportutils.nim b/eth-rpc/server/private/transportutils.nim index bdd636d..e2c58e2 100644 --- a/eth-rpc/server/private/transportutils.nim +++ b/eth-rpc/server/private/transportutils.nim @@ -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)