Skip to content

implement standard iostreams based on nng::msg#28

Open
EvanBalster wants to merge 6 commits intocwzx:masterfrom
EvanBalster:eb-iostreams
Open

implement standard iostreams based on nng::msg#28
EvanBalster wants to merge 6 commits intocwzx:masterfrom
EvanBalster:eb-iostreams

Conversation

@EvanBalster
Copy link
Copy Markdown

@EvanBalster EvanBalster commented Jul 9, 2021

This is a complete header-only implementation of the streambuf, and iostream interfaces for NNG messages.

I am not sure if supplementary features like this belong in NNGPP, but it's quite useful. As such, consider this PR tentative. I haven't yet conformed it to NNGPP's code style as I expect some discussion about whether it ought to be integrated.

For example:

nng::msg msg;
nng::omsgstream write(msg);
write << "POST /messages HTTP/1.1" << std::endl;
write << "Content-Type: text/plain" << std::endl;
write << std::endl;
write << "Hello, world" << std::endl;

This code relies on nng_msg_capacity and nng_msg_reserve functions, which I contributed to NNG only a few days ago. As such it requires the "tip" version of NNG to function.

In addition to reading and writing nng::msg like a file, a sub-range of the message may be specified using open_range or additional constructor arguments. This is intended for exposing sections of messages or omitting application-layer headers from I/O operations. The parameter scheme for specifying ranges is a recent addition and might need more thinking.

Unlike ordinary iostreams, msgbuf and msgstream are copyable, and multiple msgbuf may refer to the same message at the same time. No special provisions are made for concurrency.

I have performed basic consistency testing with this facility in my own library. If it's put into production, more detailed unit tests are probably necessary.

† Note: similar to most implementations of std::stringstream, these classes lack full support for the ios_base::app flag.

@EvanBalster EvanBalster changed the title implement streambuf/iostream (tested) implement std::ostream / std::streambuf (tested) Jul 9, 2021
@EvanBalster EvanBalster changed the title implement std::ostream / std::streambuf (tested) implement std::ostream / std::streambuf (tentative) Jul 9, 2021
@EvanBalster
Copy link
Copy Markdown
Author

I've fleshed the implementation out somewhat. I've gotten it working on osx/clang in addition to windows/msvc. It also now supports unusual character types such as std::byte and custom traits classes.

@EvanBalster EvanBalster changed the title implement std::ostream / std::streambuf (tentative) implement std::ostream / std::streambuf for nng::msg I/O Jul 31, 2021
@EvanBalster EvanBalster changed the title implement std::ostream / std::streambuf for nng::msg I/O implement std::ostream / std::streambuf for msg I/O Jul 31, 2021
@EvanBalster EvanBalster changed the title implement std::ostream / std::streambuf for msg I/O implement standard iostreams based on nng::msg Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant