Protobuf is an advanced format, and your layout is ideal for this. Just open your file at the end and start with a new (empty) BigObject . Add / serialize only a new instance of Message and write to the file (starting from the end).
Now, if you analyze your file from the very beginning, you will get a single BigObject with all Message instances (old and new).
You could do this by registering each individual Message as it arrives, if each time you wrap it in BigObject , that is, in pseudocode
loop { msg = await NextMessage(); wrapper = new BigObject(); wrapper.Messages.Add(msg); file = OpenFileAtEnd(); wrapper.WriteTo(file); file.Close(); }
source share