I\'m working with data from spinn3r, which consists of multiple different protobuf messages serialized into a byte stream:
http://code.google.com/p/spinn3r-client/wiki/P
I've implemented a small python package to serialize multiple protobuf messages into a stream and deserialize them from a stream. You can install it by pip
:
pip install pystream-protobuf
Here's a sample code writing two lists of protobuf messages in to a file:
import stream
with stream.open("test.gam", "wb") as ostream:
ostream.write(*objects_list)
ostream.write(*another_objects_list)
and then reading the same messages (e.g. Alignment messages defined in vg_pb2.py
) from the stream:
import stream
import vg_pb2
alns_list = []
with stream.open("test.gam", "rb") as istream:
for data in istream:
aln = vg_pb2.Alignment()
aln.ParseFromString(data)
alns_list.append(aln)