@@ -85,7 +85,6 @@ proc newStructContext(): StructContext =
8585 result .index = 0
8686
8787proc `$` * ( node: StructNode ): string =
88- # # Delegate stringification of `TNetstringNode` to its underlying object.
8988 return case node.kind:
9089 of StructChar :
9190 $ node.ch
@@ -98,49 +97,38 @@ proc `$`*( node: StructNode ): string =
9897 of StructString :
9998 $ node.str
10099
101- proc getChar * (node: StructNode ): char {.noSideEffect , procVar .} =
102- assert node.kind == StructChar
103- result = node.ch
100+ proc getChar * (node: StructNode ): char {.noSideEffect , inline .} =
101+ node.ch
104102
105- proc getBool * (node: StructNode ): bool {.noSideEffect , procVar .} =
106- assert node.kind == StructBool
107- result = node.bval
103+ proc getBool * (node: StructNode ): bool {.noSideEffect , inline .} =
104+ node.bval
108105
109- proc getShort * (node: StructNode ): int16 {.noSideEffect , procVar .} =
110- assert node.kind == StructInt
111- result = node.num.int16
106+ proc getShort * (node: StructNode ): int16 {.noSideEffect , inline .} =
107+ node.num.int16
112108
113- proc getUShort * (node: StructNode ): uint16 {.noSideEffect , procVar .} =
114- assert node.kind == StructInt
115- result = node.num.uint16
109+ proc getUShort * (node: StructNode ): uint16 {.noSideEffect , inline .} =
110+ node.num.uint16
116111
117- proc getInt * (node: StructNode ): int32 {.noSideEffect , procVar .} =
118- assert node.kind == StructInt
119- result = node.num.int32
112+ proc getInt * (node: StructNode ): int32 {.noSideEffect , inline .} =
113+ node.num.int32
120114
121- proc getUInt * (node: StructNode ): uint32 {.noSideEffect , procVar .} =
122- assert node.kind == StructInt
123- result = node.num.uint16
115+ proc getUInt * (node: StructNode ): uint32 {.noSideEffect , inline .} =
116+ node.num.uint16
124117
125- proc getQuad * (node: StructNode ): int64 {.noSideEffect , procVar .} =
126- assert node.kind == StructInt
127- result = node.num.int64
118+ proc getQuad * (node: StructNode ): int64 {.noSideEffect , inline .} =
119+ node.num.int64
128120
129- proc getUQuad * (node: StructNode ): uint64 {.noSideEffect , procVar .} =
130- assert node.kind == StructInt
131- result = node.num.uint64
121+ proc getUQuad * (node: StructNode ): uint64 {.noSideEffect , inline .} =
122+ node.num.uint64
132123
133- proc getFloat * (node: StructNode ): float32 {.noSideEffect , procVar .} =
134- assert node.kind == StructFloat
135- result = node.fval.float32
124+ proc getFloat * (node: StructNode ): float32 {.noSideEffect , inline .} =
125+ node.fval.float32
136126
137- proc getDouble * (node: StructNode ): float64 {.noSideEffect , procVar .} =
138- assert node.kind == StructFloat
139- result = node.fval.float64
127+ proc getDouble * (node: StructNode ): float64 {.noSideEffect , inline .} =
128+ node.fval.float64
140129
141- proc getString * (node: StructNode ): string {.noSideEffect , procVar .} =
142- assert node.kind == StructString
143- return node.str
130+ proc getString * (node: StructNode ): string {.noSideEffect , inline .} =
131+ node.str
144132
145133proc calcsize (format: string ): int =
146134 var repeat = newString (0 )
@@ -275,7 +263,7 @@ proc unpack_string(vars: var seq[StructNode], ctx: var StructContext) =
275263 else :
276264 value = ctx.buffer[ctx.offset.. ctx.offset+ ctx.repeat- 1 ]
277265 vars.add (newStructString (value))
278- ctx.offset += ctx.repeat
266+ inc ( ctx.offset, ctx.repeat)
279267
280268
281269
@@ -329,7 +317,7 @@ proc unpack*(fmt, buf: string): seq[StructNode] =
329317 of 's' :
330318 unpack_string (result , context)
331319 of 'x' :
332- context.offset += context.repeat * getSize (f)
320+ inc ( context.offset, context.repeat * getSize (f) )
333321 else :
334322 raise newException (ValueError , " bad char in struct format" )
335323
0 commit comments