Assuming I have a string
var x = "aaaabbbbbbbbcccc"
of length 16. I want to read the chars "aaaa" as int32, the chars "bbbbbbbb" as int64 and the chars "cccc" as int32.
What would be the most performant way to read these 3 slices into the int types if I know the start index (here 0)?
The link was indeed very helpful, so I used the following:
From T to string:
result = ""
var t: T
var fromTtoString = cast[ptr array[sizeof(T), char]](unsafeAddr(t))[]
for c in fromTtoString: result.add(c)
From string to T:
var t: T = cast[ptr T](unsafeAddr(serializedStringData[stringIndex]))[]