mason-0: 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

Builder 

Fields

Instances
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.

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

toLazyByteString :: BuilderFor Channel -> ByteString Source #

Create a lazy ByteString. Threaded runtime is required.

stringUtf8 :: String -> Builder 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.

hPutBuilderLen :: Handle -> BuilderFor PutBuilderEnv -> 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 :: BoundedPrim Word8 -> Text -> Builder Source #

Encode Text with a custom escaping function

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

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

data SocketEnv Source #

Environemnt for socket output

Constructors

SE 

Fields

Internal

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

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

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

Allocate a new buffer.

grisu3 :: Double -> Maybe (ByteString, Int) Source #

Decimal encoding of a positive Double.