c++ - Advantage of asio::streambuf over raw array -
c++ - Advantage of asio::streambuf over raw array -
i don't quite understand advantage of using streambuf on regular array. allow me explain problem. have network connection encrypted using rijndael 128 ecb + easy cipher encrypt remaining info shorter 16 bytes. packets structured length_of_whole_packet+operationcode+data. have re-create info streambuf can apply decryption algorithm? why making re-create of info have?
same problem have sending data. when in securedmode packet construction length_of_whole_packet+crc+data, crc , info encrypted. create monstrosity makepacket(header, format, ...) allocate array, format packet, add together crc , encrypt it, avoid vararg function. can't utilize structs packets has dynamic length because there can arrays in it, or strings. if used makepacket(unsigned char opcode, &streambuf sb) there problem crc 1 time again -> have create re-create encrypt it.
should utilize vararg monstrosity sending using regular array buffer in combination unsigned char pbyrecvbuffer[buffermaxlen] recv?
i'm not sure how design communication avoiding copies of data.
thank you answers.
when using streambufs, copying of info can minimized using algorithms operate on iterators, such std::istreambuf_iterator or boost::asio::buffers_iterator, rather copying info streambuf info structure.
for stream-like application protocols, boost::asio::streambuf superior boost::asio::buffer() compatible types, such raw array. example, consider http, delimiter used identify boundaries between variable length headers , bodies. higher-level read_until() operations provide elegant way to read protocol, boost.asio handle memory allocation, observe delimiter, , invoke completion handler 1 time message boundary has been reached. if application used raw array, need read chunks , re-create each fragmented chunk aggregated memory buffer until appropriate delimiter identified.
if application can determine exact amount of bytes read, may worth considering using boost::array fixed length portions , std::vector variable length portions. example, application protocol a:
boost::array. fixed length header contains plenty info determine length of next variable length body utilize std::vector read fixed size header, resize vector 1 time body length has been determined, read body. in context of question, if length_of_whole_packet of fixed length, application read std::vector, resize vector based on determined body length, read remaining info vector. decryption algorithm operate straight on vector , utilize output iterator, such std::back_insert_iterator, auxiliary output buffer if algorithm cannot done in-place. same holds true encrypting info written.
c++ arrays boost-asio streambuf
Comments
Post a Comment