We're thinking of using Protocol Buffers for binary logging because:
- It's how we're encoding our objects anyway
- It is relatively compact, fast to read / write etc.
That said, it isn't obvious how we should go about it because the APIs tend to focus on creating whole objects, so wrapping a list of DataLogEntry as a repeated field in a DataLogFile would be what you'd do in messaging terms but what we really want is just to be able to write and then read a whole DataLogEntry out, appending it to the end of a file.
The first issue we've hit by doing that is that doing this (in a test:
FileInputStream fileIn = new FileInputStream(logFile);
CodedInputStream in = CodedInputStream.newInstance(fileIn);
while(!in.isAtEnd()) {
DataLogEntry entry = DataLogEntry.parseFrom(in);
// ... do stuff
}
Only results in 1 DataLogEntry being read from the stream. Without the isAtEnd, it never stops.
Thoughts?
Edit: I've switched to using entry.writeDelimitedTo and BidLogEntry.parseDelimitedFrom and that seems to work...