small-bytearray-builder-0.3.2.0: Serialize to a small byte arrays

Safe HaskellNone
LanguageHaskell2010

Data.ByteArray.Builder.Unsafe

Contents

Synopsis

Types

newtype Builder Source #

An unmaterialized sequence of bytes that may be pasted into a mutable byte array.

Constructors

Builder (forall s. MutableByteArray# s -> Int# -> Int# -> Commits s -> State# s -> (#State# s, MutableByteArray# s, Int#, Int#, Commits s#)) 

data Commits s Source #

Constructors

Mutable 

Fields

Immutable 

Fields

  • ByteArray#

    Immutable chunk

  • Int#

    Offset into chunk, not necessarily zero

  • Int#

    Length (may be smaller than actual length)

  • !(Commits s)
     
Initial 

Execution

pasteST :: Builder -> BuilderState s -> ST s (BuilderState s) Source #

Run a builder, performing an in-place update on the state. The BuilderState argument must not be reused after being passed to this function. That is, its use must be affine.

Construction

fromEffect Source #

Arguments

:: Int

Maximum number of bytes the paste function needs

-> (forall s. MutableByteArray s -> Int -> ST s Int)

Paste function. Takes a byte array and an offset and returns the new offset and having pasted into the buffer.

-> Builder 

Finalization

reverseCommitsOntoChunks :: Chunks -> Commits s -> ST s Chunks Source #

Cons the chunks from a list of Commits onto an initial Chunks list (this argument is often ChunksNil). This reverses the order of the chunks, which is desirable since builders assemble Commits with the chunks backwards. This performs an in-place shrink and freezes on any mutable byte arrays it encounters. Consequently, these must not be reused.

copyReverseCommits Source #

Arguments

:: MutableByteArray s

Destination

-> Int

Destination range successor

-> Commits s

Source

-> ST s Int 

Copy the contents of the chunks into a mutable array, reversing the order of the chunks. Precondition: The destination must have enough space to house the contents. This is not checked.

addCommitsLength :: Int -> Commits s -> Int Source #

Add the total number of bytes in the commits to first argument.

Safe Functions

These functions are actually completely safe, but they are defined here because they are used by typeclass instances. Import them from Data.ByteArray.Builder instead.

stringUtf8 :: String -> Builder Source #

Create a builder from a cons-list of Char. These are be UTF-8 encoded.

cstring :: CString -> Builder Source #

Create a builder from a NUL-terminated CString. This ignores any textual encoding, copying bytes until NUL is reached.