-
Notifications
You must be signed in to change notification settings - Fork 44
Closed
Description
With those two convert list of nums to string to use as a key or value and back :
# list of numbers =to=> string
def nums2str(nums, itype='H'): #B:int8,H:int16,I:int32,Q:int64
return struct.pack(f">{len(nums)}{itype}", *nums)
#string =2=> tuple of numbers, use list()
def str2nums(b, itype='H'):
size = 1 if itype == 'B' else ('HIQ'.index(itype) + 1) * 2
return struct.unpack(f">{len(b)//size}{itype}", bytes(b,'utf-8'))
index.Set(nums2str([454,7889]), nums2str([1,2,3,4]))
m = index.Get(nums2str([454,7889])
res = str2nums(m.GetValue())
u can add this to the docs
bytes(b,'utf-8') : assumes u got back string if u got bytestring just use 'b' directly
hendrikmuhs and vsraptor
Metadata
Metadata
Assignees
Labels
No labels