Why does CodedInputStream set the position of the stream to complete?

I use protocol buffers 3 in C #. I am trying to bounce through a stream to find the starting locations of each message, without actually deserialising the messages. All messages are written to the stream using WriteDelimitedTo .

Then I use this code to try moving from length markers:

 _map = new List<int>(); _stream.Seek(0, SeekOrigin.Begin); var codedStream = new CodedInputStream(_stream); while (_stream.Position < _stream.Length) { var length = codedStream.ReadInt32(); _map.Add((int) _stream.Position); _stream.Seek(length, SeekOrigin.Current); } 

However, the moment I do codedStream.ReadInt32() , the position of the stream is set to the end, not just the next byte after varint32.

+1
c # protocol-buffers
Nov 16 '15 at 11:08
source share
1 answer

This behavior is due to CodedInputStream buffering the source stream as you can see in the source code . This is probably not suitable for manual reading and searching through a stream. An alternative is to use parts of the Mark Gravell source code to read the varint available here , and navigate in a direct stream directly.

+1
Feb 23 '16 at 9:12
source share



All Articles