I have an array with two elements: the first is type, the second is a data array I need to convert.
[['string','int32','string','int64','float32','string','string'],['any string','19','any string','198732132451654654','0.6','any string','any string']]
I know how to convert integer to binary, but in the above array with multiple types, how do I convert it to binary?
Although you’ve accepted my other answer, after noticing your comment explaining that what you really wanted was to convert the data into binary using
struct.pack(), I’ve written another that might suit you even better (despite being longer and a little more complicated).Output:
The
TypeConv.pack()method first converts the string value to its equivalent Python valuepy_value, then usesstruct.pack()to convert that to a C binary value — which I think is what you seek.