That's a good idea. I'll try that. Thanks. Mark
On Sun, Dec 13, 2009 at 12:50 PM, Nick Bolton <[email protected]> wrote: > Hi Mark, > >> Comments welcome. >> Mark >> >> >> class ProtocolBufferFileReader: >> def __init__(self, input_filename, message_constructor): >> self.file = open(input_filename, 'rb') >> self.message_constructor = message_constructor > > It may also be useful to modify this constructor to accept a "file" argument: > > class ProtocolBufferFileReader: > def __init__(self, file, message_constructor): > self.file = file > self.message_constructor = message_constructor > > So that you can call the class in two ways: > > reader = ProtocolBufferFileReader(open(input_filename, 'rb')) > > ... or ... > > from cStringIO import StringIO > reader = ProtocolBufferFileReader(StringIO(binary_data)) > > ... where binary_data is a Python binary string created by > myMessage.SerializeToString() > > This would be useful for receiving several protobuf messages over the > network at once (for example). It also means that you don't need to > modify the existing code in ProtocolBufferFileReader, since StringIO > also has the same read, write, seek, and tell functions as the file > class. It's a bit like using a stream in C++ I suppose. > > Nick > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
