@@ -13,6 +13,8 @@ import endians
1313import macros
1414
1515type
16+ SomeByte * = byte | char | int8 | uint8
17+
1618 StructError * = object of OSError
1719
1820 StructKind * = enum # # possible JSON node types
@@ -62,7 +64,7 @@ proc newStructChar*(c: char): StructNode = StructNode(kind: StructChar, ch: c)
6264
6365proc newStructBool * (b: bool ): StructNode = StructNode (kind: StructBool , bval: b)
6466
65- proc newStructInt * [T: uint | int | int16 | uint16 | int32 | uint32 | int64 | uint64 | BiggestInt ](i: T): StructNode =
67+ proc newStructInt * [T: SomeInteger ](i: T): StructNode =
6668 result = StructNode (kind: StructInt , num: i.BiggestInt )
6769
6870proc newStructFloat * (d: BiggestFloat ): StructNode = StructNode (kind: StructFloat , fval: d)
@@ -98,19 +100,19 @@ proc getShort*(node: StructNode): int16 {.noSideEffect, inline.} =
98100 node.num.int16
99101
100102proc getUShort * (node: StructNode ): uint16 {.noSideEffect , inline .} =
101- node.num.uint16
103+ node.num.uint . uint16
102104
103105proc getInt * (node: StructNode ): int32 {.noSideEffect , inline .} =
104106 node.num.int32
105107
106108proc getUInt * (node: StructNode ): uint32 {.noSideEffect , inline .} =
107- node.num.uint32
109+ node.num.uint . uint32
108110
109111proc getQuad * (node: StructNode ): int64 {.noSideEffect , inline .} =
110112 node.num.int64
111113
112114proc getUQuad * (node: StructNode ): uint64 {.noSideEffect , inline .} =
113- node.num.uint64
115+ node.num.uint . uint64
114116
115117proc getFloat * (node: StructNode ): float32 {.noSideEffect , inline .} =
116118 node.fval.float32
@@ -145,19 +147,19 @@ proc parse_prefix(ctx: var StructContext, f: char) =
145147 else :
146148 ctx.byteOrder = system.cpuEndian
147149
148- proc load_16 * [T:byte | char | int8 | uint8 ](a, b: T, endian: Endianness ): int16 {.inline .} =
150+ proc load_16 * [T: SomeByte ](a, b: T, endian: Endianness ): int16 {.inline .} =
149151 if endian == littleEndian:
150152 a.int16 + b.int16 shl 8
151153 else :
152154 b.int16 + a.int16 shl 8
153155
154- proc load_32 * [T:byte | char | int8 | uint8 ](a, b, c, d: T, endian: Endianness ): int32 {.inline .} =
156+ proc load_32 * [T: SomeByte ](a, b, c, d: T, endian: Endianness ): int32 {.inline .} =
155157 if endian == littleEndian:
156158 a.int32 + b.int32 shl 8 + c.int32 shl 16 + d.int32 shl 24
157159 else :
158160 d.int32 + c.int32 shl 8 + b.int32 shl 16 + a.int32 shl 24
159161
160- proc load_32f * [T:byte | char | int8 | uint8 ](a, b, c, d: T, endian: Endianness ): float32 {.inline .} =
162+ proc load_32f * [T: SomeByte ](a, b, c, d: T, endian: Endianness ): float32 {.inline .} =
161163 var o = cast [cstring ](addr result )
162164 if endian == littleEndian:
163165 o[0 ] = a
@@ -257,7 +259,6 @@ proc unpack_string(vars: var seq[StructNode], ctx: var StructContext) =
257259 inc (ctx.offset, ctx.repeat)
258260
259261
260-
261262proc unpack * (fmt, buf: string ): seq [StructNode ] =
262263 result = @ []
263264
@@ -458,7 +459,7 @@ proc add*(s: var Struct, c: char) {.inline.} =
458459proc add * (s: var Struct , b: bool ) {.inline .} =
459460 s.vars.add (newStructBool (b))
460461
461- proc add * [T: uint | int | int16 | uint16 | int32 | uint32 | int64 | uint64 | BiggestInt ](s: var Struct , d: T) {.inline .} =
462+ proc add * [T: SomeNumber | BiggestInt ](s: var Struct , d: T) {.inline .} =
462463 s.vars.add (newStructInt (d))
463464
464465proc add * (s: var Struct , d: float ) {.inline .} =
0 commit comments