i have block of msgpack'd data created shown below:
#!/usr/bin/env python io import bytesio import msgpack packer = msgpack.packer() buf = bytesio() buf.write(packer.pack("foo")) buf.write(packer.pack("bar")) buf.write(packer.pack("baz"))
later in app (or different app) need unpack first 2 elements want access third element still packed. way have found far repack third element shown below, rather inefficient.
buf.seek(0) unpacker = msgpack.unpacker(buf) item1 = unpacker.unpack() item2 = unpacker.unpack() item3 = unpacker.unpack() packed_item3 = msgpack.pack(item3)
this gets me want, prefer access this last item directly can pass on needs go packed.
since packs not of constant size after doing msgpack, can use identifiable set of bytes seperator of packs. when need direct access nth pack, still in packed state, iterate on byte array, , nth pack lie after n-1 th seperator. though have o(n) complexity , need iteration on whole bytearray till required pack. string example "####" seperator :
"pack1####pack2####pack3####pack4####pack5...."
Comments
Post a Comment