diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-11-01 17:23:11 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-11-01 17:23:11 +0200 |
commit | aa18910e4dd78463c07f7f3ef84e1c5b137219cb (patch) | |
tree | ad3a7d680771e8f8368420333e159520e34a75ab | |
parent | 1dac14cdd0c1c87cf99cee6aedc956b1caf92845 (diff) | |
download | obnam-liw/optnop.tar.gz |
Handle number of strings with struct.packliw/optnop
This avoids a bit of extra parsing. It limits us to lists of
2**64-1 items, but I think we can live with that.
-rw-r--r-- | obnamlib/obj_serialiser.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/obnamlib/obj_serialiser.py b/obnamlib/obj_serialiser.py index ccc0a722..b39505d9 100644 --- a/obnamlib/obj_serialiser.py +++ b/obnamlib/obj_serialiser.py @@ -187,13 +187,16 @@ def _deserialise_dict(serialised): def _serialise_str_list(strings): n = len(strings) + encoded_n = struct.pack('!Q', n) encoded_lengths = struct.pack('!' + 'Q' * n, *[len(s) for s in strings]) - return _serialise_integer(n) + encoded_lengths + ''.join(strings) + return encoded_n + encoded_lengths + ''.join(strings) def _deserialise_str_list(serialised, pos): - n, pos = _deserialise_prefix(serialised, pos) int_size = struct.calcsize('!Q') + n = struct.unpack('!Q', serialised[pos:pos+int_size])[0] + pos += int_size + lengths = struct.unpack('!' + 'Q' * n, serialised[pos:pos + n*int_size]) pos += n * int_size strings = [] |