On Jun 25, 2010, at 4:40 , Louis-Marie wrote:
My question is then: how can I safely detect end of file? I guess I
could do something like calling Next() on the underlying
FileInputStream until it returns false (end of file) or a non empty
buffer (and then call BackUp() to re-queue this buffer before creating
the CodedInputStream), but it seems a bit overkill (and probably not
the best thing from a performance point of view...)
I think that detecting the end of file may depend on your underlying
input stream. I have some code that uses the built-in FileInputStream,
and I simply keep trying to read values until I get an error:
bool success = in.ReadVarint32(&size);
if (!success) {
// we are probably at EOF
close();
return;
}
Then my close() method looks like:
assert(input_->GetErrno() == 0);
bool success = input_->Close();
assert(success);
This works for me.
Evan
--
Evan Jones
http://evanjones.ca/
--
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.