| |||||||||||||||||
| |||||||||||||||||
| |||||||||||||||||
Description | |||||||||||||||||
Writes and Builders for strict and lazy bytestrings. We assume the following qualified imports in order to differentiate between strict and lazy bytestrings in the code examples. import qualified Data.ByteString as S import qualified Data.ByteString.Lazy as L | |||||||||||||||||
Synopsis | |||||||||||||||||
| |||||||||||||||||
Strict bytestrings | |||||||||||||||||
writeByteString :: ByteString -> Write | |||||||||||||||||
Write a strict ByteString to a buffer. | |||||||||||||||||
fromByteString :: ByteString -> Builder | |||||||||||||||||
Smart serialization of a strict bytestring. fromByteString = fromByteStringWith defaultMaximalCopySize Use this function to serialize strict bytestrings. It guarantees an average chunk size of 4kb, which has been shown to be a reasonable size in benchmarks. Note that the check whether to copy or to insert is (almost) free as the builder performance is mostly memory-bound. If you statically know that copying or inserting the strict bytestring is always the best choice, then you can use the copyByteString or insertByteString functions. | |||||||||||||||||
fromByteStringWith | |||||||||||||||||
| |||||||||||||||||
copyByteString :: ByteString -> Builder | |||||||||||||||||
copyByteString bs serialize the strict bytestring bs by copying it to the output buffer. Use this function to serialize strict bytestrings that are statically known to be smallish (<= 4kb). | |||||||||||||||||
insertByteString :: ByteString -> Builder | |||||||||||||||||
insertByteString bs serializes the strict bytestring bs by inserting it directly as a chunk of the output stream. Note that this implies flushing the output buffer; even if it contains just a single byte. Hence, you should use this operation only for large (> 8kb) bytestrings, as otherwise the resulting output stream may be too fragmented to be processed efficiently. | |||||||||||||||||
Lazy bytestrings | |||||||||||||||||
fromLazyByteString :: ByteString -> Builder | |||||||||||||||||
O(n). Smart serialization of a lazy bytestring. fromLazyByteString = fromLazyByteStringWith defaultMaximalCopySize Use this function to serialize lazy bytestrings. It guarantees an average chunk size of 4kb, which has been shown to be a reasonable size in benchmarks. Note that the check whether to copy or to insert is (almost) free as the builder performance is mostly memory-bound. If you statically know that copying or inserting all chunks of the lazy bytestring is always the best choice, then you can use the copyLazyByteString or insertLazyByteString functions. | |||||||||||||||||
fromLazyByteStringWith | |||||||||||||||||
| |||||||||||||||||
copyLazyByteString :: ByteString -> Builder | |||||||||||||||||
O(n). Serialize a lazy bytestring by copying all chunks sequentially to the output buffer. See copyByteString for usage considerations. | |||||||||||||||||
insertLazyByteString :: ByteString -> Builder | |||||||||||||||||
O(n). Serialize a lazy bytestring by inserting all its chunks directly into the output stream. See insertByteString for usage considerations. For library developers, see the ModifyChunks build signal, if you need an O(1) lazy bytestring insert based on difference lists. | |||||||||||||||||
Produced by Haddock version 2.6.0 |