I'm using LMDB to store objects serialized by the excellent NESM library.
Unfortunately, LMDB wants its data to be of type void*, and my serialized
objects are all strings. At first, this wasn't a concern - I just set the data
field to
> addr myString
Unfortunately though, this doesn't work. I was able to get farther by creating
a fixed array of characters and then filling that in with the information in my
string like so:
proc asArray*(s: string, arr: var openarray[char]): void =
if s.len < arr.len:
for i, c in s:
arr[i] = c
else:
quit("Not enough space available for that!", -1)
but this assumes that whatever array I'm referencing is of a fixed length.
While this approach does work, I would rather not create a one size fits all
array[5000, char] if most of the time my strings are quite small.
I know there has to be an easy approach, I'm just not familiar enough with Nim
and how it interfaces with C to invoke the correct magic via string or cstring
alone. Any help would be greatly appreciated!