@@ -123,7 +123,8 @@ proc getDouble*(node: StructNode): float64 {.noSideEffect, inline.} =
123
123
proc getString * (node: StructNode ): string {.noSideEffect , inline .} =
124
124
node.str
125
125
126
- proc calcsize (format: string ): int =
126
+ proc computeLength * (format: string ): int =
127
+ # # Compute the length for string represent `format`
127
128
var repeat = newString (0 )
128
129
for i in 0 .. format.len- 1 :
129
130
let f: char = format[i]
@@ -262,9 +263,9 @@ proc unpack_string(vars: var seq[StructNode], ctx: var StructContext) =
262
263
proc unpack * (fmt, buf: string ): seq [StructNode ] =
263
264
result = @ []
264
265
265
- let size = calcsize (fmt)
266
- if buf.len < size :
267
- raise newException (ValueError , " unpack requires a string argument of length " & $ size & " , input: " & $ buf.len)
266
+ let length = computeLength (fmt)
267
+ if buf.len < length :
268
+ raise newException (ValueError , " unpack requires a string argument of length " & $ length & " , input: " & $ buf.len)
268
269
269
270
var context = newStructContext ()
270
271
context.buffer = buf
@@ -407,7 +408,7 @@ proc pack_pad(result: var string, ctx: var StructContext) =
407
408
inc (ctx.index, ctx.repeat)
408
409
409
410
proc pack * (fmt: string , vars: varargs [StructNode ]): string =
410
- result = newString (calcsize (fmt))
411
+ result = newString (computeLength (fmt))
411
412
var context = newStructContext ()
412
413
var repeat = newString (0 )
413
414
for i in 0 .. fmt.len- 1 :
0 commit comments