mirror of
https://github.com/FossifyOrg/Messages.git
synced 2026-06-17 21:11:05 -04:00
This significantly reduces memory usage. (We buffer the OutputStream because kotlinx.serialization flushes its internal buffers excessively[1]. We also buffer the InputStream for consistency, even though kotlinx.serialization uses adequate buffering; there is no performance impact because BufferedInputStream cascades harmlessly[2].) The functions encodeToStream() and decodeFromStream() are marked as experimental, but this is a pretty fundamental use case so surely it will continue to be supported in the future (maybe with minor changes). Fixes #6. [1] https://github.com/Kotlin/kotlinx.serialization/blob/v1.6.3/formats/json/jvmMain/src/kotlinx/serialization/json/internal/JvmJsonStreams.kt#L46 [2] https://github.com/openjdk/jdk/blob/jdk-23%2B14/src/java.base/share/classes/java/io/BufferedInputStream.java#L339