I've implemented a noise crypto stream wrapper for vibe.D: http://code.dlang.org/packages/vibe-noisestream

Currently whenever a user calls write(ubyte[]) I simply encrypt that data and call the downstream write function. However, if the users writes many small packets that increases the protocol overhead as every encrypted packet needs additional 2+16 bytes for crypto. So I was wondering whether it is safe to concat the data from multiple writes and send it only when the internal buffer is full or the user calls flush. Is it reasonable to expect users to properly flush streams?

Another unrelated problem, maybe someone has got a good idea: The upcoming noisesocket protocol will likely allow packets up to 2^16-1 bytes. A packet can only be decrypted at once so the complete packet needs top be cached. This leads to huge buffers which is especially annoying when using many streams in parallel. So has anyone already thought about or implemented some kind of buffer sharing between streams / Fibers in vibe.d?