mason-0.2.4: Fast and extensible bytestring builder
Safe HaskellNone
LanguageHaskell2010

Mason.Builder.Internal

Contents

Synopsis

Documentation

type Builder = forall s. Buildable s => BuilderFor s Source #

The Builder type. Requires RankNTypes extension

newtype BuilderFor s Source #

Builder specialised for a backend

Constructors

RawBuilder 

Fields

Instances

Instances details
Buildable s => IsString (BuilderFor s) Source # 
Instance details

Defined in Mason.Builder.Internal

Methods

fromString :: String -> BuilderFor s #

Semigroup (BuilderFor s) Source # 
Instance details

Defined in Mason.Builder.Internal

Monoid (BuilderFor a) Source # 
Instance details

Defined in Mason.Builder.Internal

class Buildable s where Source #

This class is used to provide backend-specific operations for running a Builder.

Minimal complete definition

flush, allocate

Methods

byteString :: ByteString -> BuilderFor s Source #

Put a ByteString.

flush :: BuilderFor s Source #

Flush the content of the internal buffer.

allocate :: Int -> BuilderFor s Source #

Allocate a buffer with at least the given length.

data Buffer Source #

Buffer pointers

Constructors

Buffer 

Fields

pattern Builder :: (s -> Buffer -> IO Buffer) -> BuilderFor s Source #

toLazyByteString :: BuilderFor LazyByteStringBackend -> ByteString Source #

Create a lazy ByteString. Threaded runtime is required.

stringUtf8 :: Buildable s => String -> BuilderFor s Source #

UTF-8 encode a String.

lengthPrefixedWithin Source #

Arguments

:: Int

maximum length

-> BoundedPrim Int

prefix encoder

-> BuilderFor () 
-> Builder 

Run a builder within a buffer and prefix it by the length.

data PutEnv Source #

Environment for handle output

Constructors

PutEnv 

Fields

hPutBuilderLen :: Handle -> BuilderFor BufferedIOBackend -> IO Int Source #

Write a Builder into a handle and obtain the number of bytes written. flush does not imply actual disk operations. Set NoBuffering if you want it to write the content immediately.

encodeUtf8BuilderEscaped :: Buildable s => BoundedPrim Word8 -> Text -> BuilderFor s Source #

Encode Text with a custom escaping function

sendBuilder :: Socket -> BuilderFor BufferedIOBackend -> IO Int Source #

Write a Builder into a handle and obtain the number of bytes written.

withPtr Source #

Arguments

:: Buildable s 
=> Int

number of bytes to allocate (if needed)

-> (Ptr Word8 -> IO (Ptr Word8))

return a next pointer after writing

-> BuilderFor s 

Construct a Builder from a "poke" function.

storable :: Storable a => a -> Builder Source #

Turn a Storable value into a Builder

paddedBoundedPrim Source #

Arguments

:: Word8

filler

-> Int

pad if shorter than this

-> BoundedPrim a 
-> a 
-> Builder 

Internal

ensure :: Int -> (Buffer -> IO Buffer) -> Builder Source #

Ensure that the given number of bytes is available in the buffer. Subject to semigroup fusion

allocateConstant :: (s -> IORef (ForeignPtr Word8)) -> Int -> BuilderFor s Source #

Allocate a new buffer.

withGrisu3 :: Double -> IO r -> (Ptr Word8 -> Int -> Int -> IO r) -> IO r Source #

Decimal encoding of a positive Double.

withGrisu3Rounded :: Int -> Double -> (Ptr Word8 -> Int -> Int -> IO r) -> IO r Source #

roundDigit Source #

Arguments

:: Int

precision

-> Int

available digits

-> Ptr Word8

content

-> IO Bool 

Round up to the supplied precision inplace.