Commit 36d8dc7a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 000f662b
...@@ -63,6 +63,29 @@ def init(zstor): ...@@ -63,6 +63,29 @@ def init(zstor):
transaction.commit() transaction.commit()
# kvEncode encodes key->value maping into text.
# e.g. {1:'a', 2:'b'} -> '1:a,2:b'
def kvEncode(kvDict, vencode): # -> kvText
retv = []
for k in sorted(kvDict.keys()):
v = kvDict[k]
retv.append('%d:%s' % (k, vencode(v)))
return ','.join(retv)
# kvDecode decodes key->value mapping from text.
# e.g. '1:a,2:b' -> {1:'a', 2:'b'}
def kvDecode(kvText, vdecode): # -> kvDict
kv = {}
for item in kvText.split(','):
ktxt, vtxt = item.split(':')
k = int(ktxt)
v = vdecode(vtxt)
if k in kv:
raise ValueError("key %s present multiple times" % k)
kv[k] = v
return kv
# XXX # XXX
# #
# kv: k₁:v₁,k₂:v₂,... # kv: k₁:v₁,k₂:v₂,...
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment