@@ -13,6 +13,8 @@ import endians
13
13
import macros
14
14
15
15
type
16
+ SomeByte* = byte | char | int8 | uint8
17
+
16
18
StructError* = object of OSError
17
19
18
20
StructKind* = enum # # possible JSON node types
@@ -62,7 +64,7 @@ proc newStructChar*(c: char): StructNode = StructNode(kind: StructChar, ch: c)
62
64
63
65
proc newStructBool* (b: bool ): StructNode = StructNode(kind: StructBool, bval: b)
64
66
65
- proc newStructInt* [T: uint | int | int16 | uint16 | int32 | uint32 | int64 | uint64 | BiggestIn t ](i: T): StructNode =
67
+ proc newStructInt* [T: SomeIntege r ](i: T): StructNode =
66
68
result = StructNode(kind: StructInt, num: i.BiggestInt)
67
69
68
70
proc newStructFloat*(d: BiggestFloat): StructNode = StructNode(kind: StructFloat, fval: d)
@@ -98,19 +100,19 @@ proc getShort*(node: StructNode): int16 {.noSideEffect, inline.} =
98
100
node.num.int16
99
101
100
102
proc getUShort*(node: StructNode): uint16 {.noSideEffect, inline.} =
101
- node.num.uint16
103
+ node.num.uint . uint16
102
104
103
105
proc getInt*(node: StructNode): int32 {.noSideEffect, inline.} =
104
106
node.num.int32
105
107
106
108
proc getUInt*(node: StructNode): uint32 {.noSideEffect, inline.} =
107
- node.num.uint32
109
+ node.num.uint . uint32
108
110
109
111
proc getQuad*(node: StructNode): int64 {.noSideEffect, inline.} =
110
112
node.num.int64
111
113
112
114
proc getUQuad*(node: StructNode): uint64 {.noSideEffect, inline.} =
113
- node.num.uint64
115
+ node.num.uint . uint64
114
116
115
117
proc getFloat*(node: StructNode): float32 {.noSideEffect, inline.} =
116
118
node.fval.float32
@@ -145,19 +147,19 @@ proc parse_prefix(ctx: var StructContext, f: char) =
145
147
else:
146
148
ctx.byteOrder = system.cpuEndian
147
149
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.} =
149
151
if endian == littleEndian:
150
152
a.int16 + b.int16 shl 8
151
153
else:
152
154
b.int16 + a.int16 shl 8
153
155
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.} =
155
157
if endian == littleEndian:
156
158
a.int32 + b.int32 shl 8 + c.int32 shl 16 + d.int32 shl 24
157
159
else:
158
160
d.int32 + c.int32 shl 8 + b.int32 shl 16 + a.int32 shl 24
159
161
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.} =
161
163
var o = cast[cstring ](addr result )
162
164
if endian == littleEndian:
163
165
o[ 0] = a
@@ -257,7 +259,6 @@ proc unpack_string(vars: var seq[StructNode], ctx: var StructContext) =
257
259
inc(ctx.offset, ctx.repeat)
258
260
259
261
260
-
261
262
proc unpack* (fmt, buf: string ): seq [StructNode] =
262
263
result = @ []
263
264
@@ -458,7 +459,7 @@ proc add*(s: var Struct, c: char) {.inline.} =
458
459
proc add* (s: var Struct, b: bool ) {.inline.} =
459
460
s.vars.add(newStructBool(b))
460
461
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.} =
462
463
s.vars.add(newStructInt(d))
463
464
464
465
proc add*(s: var Struct, d: float ) {.inline.} =
0 commit comments