Mark Spanbroek 971cdad25d Simplify encoding/decoding of signed integers
Fixes error in Nim 1.4.8
2021-12-09 11:48:14 +01:00

18 lines
479 B
Nim

import pkg/stint
template unsigned*(T: type SomeSignedInt): type SomeUnsignedInt =
when T is int8: uint8
elif T is int16: uint16
elif T is int32: uint32
elif T is int64: uint64
else: {.error "unsupported signed integer type".}
template unsigned*(T: type StInt): type StUint =
StUint[T.bits]
func unsigned*(value: SomeSignedInt): SomeUnsignedInt =
cast[typeof(value).unsigned](value)
func unsigned*[bits](value: StInt[bits]): StUint[bits] =
value.stuint(bits)