-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test 1-byte reads #86
Comments
Hi! It's a good idea! Could you tell more about used scenario? What parsers do you test? |
Sure. I had the same issue in the past, but then I'd just mock the read routines and force 1-byte reads through the mocks. I don't like this approach as effectively I won't be testing the same code going into production (the read routines change). A few hours ago I was facing this issue again and I thought of searching for a new solution and FUSE seemed like a good idea and I've stumbled upon your project. So, “why not ask?” is what I've thought. For my current project, I have a routine such as follows: for (;;) {
std::string_view buffer_view(buffer.data(), buffer_used);
auto lf = buffer_view.find('\n');
if (lf != std::string_view::npos) {
line = buffer_view.substr(0, lf + 1);
break;
}
if (buffer.size() == buffer_used)
buffer.resize(buffer.size() * 2);
ssize_t nread = read(iobuf->fd,
const_cast<char*>(buffer.data()) + buffer_used,
buffer.size() - buffer_used);
if (nread == -1) {
*errcode = errno;
return EOF;
}
if (nread == 0) {
if (buffer_used == 0)
return EOF;
line = std::string_view{buffer.data(), buffer_used};
break;
}
buffer_used += nread;
} In short, I read LF-delimited records. The code is very simple and I'm not afraid of it. However I'll have to change this read-loop to use a chunked JSON parser to find the record delimiter. The chunked JSON parser maintains pointers to the stream. If I fuck it up, the parser will keep references to invalid memory. That's a much more complex beast. I'd like to run the tests ensuring that every |
I'll try to include it in the next release. |
Thanks. |
Could there be an option where
read()
only reads 1 byte at a time? It'd be useful to test buffer management routines on parsers.The text was updated successfully, but these errors were encountered: