The core datatypes of Data.ByteString.Builder
are
newtype Builder = Builder (forall r. BuildStep r -> BuildStep r)
type BuildStep a = BufferRange -> IO (BuildSignal a)
data BuildSignal a =
Done {-# UNPACK #-} !(Ptr Word8) a
| BufferFull
{-# UNPACK #-} !Int
{-# UNPACK #-} !(Ptr Word8)
(BuildStep a)
| InsertChunk
{-# UNPACK #-} !(Ptr Word8)
S.ByteString
(BuildStep a)
What purpose does the type parameter (r
or a
) serve?
In short, use bytestring s when your data is processed and stored in bytes. Bytes objects are immutable sequences of single bytes. The documentation has a very good explanation of what they are and how to use them. Ok, so it says "Only ASCII characters are permitted in bytes literals (regardless of the declared source code encoding).
Create a Builder denoting the same sequence of bytes as a strict ByteString . The Builder inserts large ByteString s directly, but copies small ones to ensure that the generated chunks are large on average. Create a Builder denoting the same sequence of bytes as a lazy ByteString .
byteString :: ByteString -> Builder Source #. Create a Builder denoting the same sequence of bytes as a strict ByteString. The Builder inserts large ByteStrings directly, but copies small ones to ensure that the generated chunks are large on average.
Immutable sequence of bytes. Provides conversions to and from byte [], String, ByteBuffer, InputStream, OutputStream. Also provides a conversion to CodedInputStream . Like String, the contents of a ByteString can never be observed to change, not even in the presence of a data race or incorrect API usage in the client code.
It is not needed. As proof, I have created a fork which does not change any of the public APIs -- only the API of modules named Internal
-- but removes this type argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With