Ingrid
Ingrid

Reputation: 173

Calculating the size of Array::pack format string

How do you calculate the length of the string that would be returned by Array::pack? Is there something like Python's calcsize?

Upvotes: 3

Views: 453

Answers (2)

user163365
user163365

Reputation: 1327

array.pack("").count I would say. Not really the fastest method, but it works.

Upvotes: 1

Mikael Jansson
Mikael Jansson

Reputation: 4841

By making an interpreter complying to the specifications found in Array::pack.

Or, reusing the existing implementation to count the number of characters instead of appending them to a string.

Upvotes: 0

Related Questions