Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Builder
- construct :: (forall s. MutableBytes s -> ST s (Maybe Int)) -> Builder
- fromBounded :: Nat n -> Builder n -> Builder
- run :: Int -> Builder -> ByteArray
- pasteST :: Builder -> MutableBytes s -> ST s (Maybe Int)
- pasteIO :: Builder -> MutableBytes RealWorld -> IO (Maybe Int)
- pasteGrowST :: Int -> Builder -> MutableByteArrayOffset s -> ST s (MutableByteArrayOffset s)
- pasteGrowIO :: Int -> Builder -> MutableByteArrayOffset RealWorld -> IO (MutableByteArrayOffset RealWorld)
- pasteArrayST :: MutableBytes s -> (a -> Builder) -> Vector a -> ST s (Vector a, MutableBytes s)
- pasteArrayIO :: MutableBytes RealWorld -> (a -> Builder) -> Vector a -> IO (Vector a, MutableBytes RealWorld)
- bytes :: Bytes -> Builder
- bytearray :: ByteArray -> Builder
- shortTextUtf8 :: ShortText -> Builder
- shortTextJsonString :: ShortText -> Builder
- cstring :: CString -> Builder
- stringUtf8 :: String -> Builder
- word64Dec :: Word64 -> Builder
- word32Dec :: Word32 -> Builder
- word16Dec :: Word16 -> Builder
- word8Dec :: Word8 -> Builder
- wordDec :: Word -> Builder
- int64Dec :: Int64 -> Builder
- int32Dec :: Int32 -> Builder
- int16Dec :: Int16 -> Builder
- int8Dec :: Int8 -> Builder
- intDec :: Int -> Builder
- word64PaddedUpperHex :: Word64 -> Builder
- word32PaddedUpperHex :: Word32 -> Builder
- word16PaddedUpperHex :: Word16 -> Builder
- word16PaddedLowerHex :: Word16 -> Builder
- word16LowerHex :: Word16 -> Builder
- word16UpperHex :: Word16 -> Builder
- word8PaddedUpperHex :: Word8 -> Builder
- word8LowerHex :: Word8 -> Builder
- ascii :: Char -> Builder
- char :: Char -> Builder
- word64BE :: Word64 -> Builder
- word32BE :: Word32 -> Builder
- word16BE :: Word16 -> Builder
- word8 :: Word8 -> Builder
- doubleDec :: Double -> Builder
Bounded Primitives
An unmaterialized sequence of bytes that may be pasted into a mutable byte array.
construct :: (forall s. MutableBytes s -> ST s (Maybe Int)) -> Builder Source #
Constructor for Builder
that works on a function with lifted
arguments instead of unlifted ones. This is just as unsafe as the
actual constructor.
fromBounded :: Nat n -> Builder n -> Builder Source #
Convert a bounded builder to an unbounded one. If the size
is a constant, use Arithmetic.Nat.constant
as the first argument
to let GHC conjure up this value for you.
Evaluation
Run a builder. An accurate size hint is important for good performance. The size hint should be slightly larger than the actual size.
pasteST :: Builder -> MutableBytes s -> ST s (Maybe Int) Source #
Execute the builder, pasting its contents into a buffer.
If the buffer is not large enough, this returns Nothing
.
Otherwise, it returns the index in the buffer that follows
the payload just written.
:: Int | How many bytes to grow by at a time |
-> Builder | |
-> MutableByteArrayOffset s | Initial buffer, used linearly. Do not reuse this argument. |
-> ST s (MutableByteArrayOffset s) | Final buffer that accomodated the builder. |
Paste the builder into the byte array starting at offset zero. This repeatedly reallocates the byte array if it cannot accomodate the builder, replaying the builder each time.
:: Int | How many bytes to grow by at a time |
-> Builder | |
-> MutableByteArrayOffset RealWorld | Initial buffer, used linearly. Do not reuse this argument. |
-> IO (MutableByteArrayOffset RealWorld) | Final buffer that accomodated the builder. |
Variant of pasteGrowST
that runs in IO
.
:: MutableBytes s | Buffer |
-> (a -> Builder) | Builder |
-> Vector a | Elements to serialize |
-> ST s (Vector a, MutableBytes s) | Shifted vector, shifted buffer |
Fold over a vector, applying the builder to each element until the buffer cannot accomodate any more.
:: MutableBytes RealWorld | Buffer |
-> (a -> Builder) | Builder |
-> Vector a | Elements to serialize |
-> IO (Vector a, MutableBytes RealWorld) | Shifted vector, shifted buffer |
Variant of pasteArrayST
that runs in IO
.
Materialized Byte Sequences
shortTextUtf8 :: ShortText -> Builder Source #
Create a builder from text. The text will 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.
stringUtf8 :: String -> Builder Source #
Create a builder from a cons-list of Char
. These
are be UTF-8 encoded.
Encode Integral Types
Human-Readable
word64Dec :: Word64 -> Builder Source #
Encodes an unsigned 64-bit integer as decimal. This encoding never starts with a zero unless the argument was zero.
word32Dec :: Word32 -> Builder Source #
Encodes an unsigned 16-bit integer as decimal. This encoding never starts with a zero unless the argument was zero.
word16Dec :: Word16 -> Builder Source #
Encodes an unsigned 16-bit integer as decimal. This encoding never starts with a zero unless the argument was zero.
word8Dec :: Word8 -> Builder Source #
Encodes an unsigned 8-bit integer as decimal. This encoding never starts with a zero unless the argument was zero.
wordDec :: Word -> Builder Source #
Encodes an unsigned machine-sized integer as decimal. This encoding never starts with a zero unless the argument was zero.
int64Dec :: Int64 -> Builder Source #
Encodes a signed 64-bit integer as decimal. This encoding never starts with a zero unless the argument was zero. Negative numbers are preceded by a minus sign. Positive numbers are not preceded by anything.
int32Dec :: Int32 -> Builder Source #
Encodes a signed 32-bit integer as decimal. This encoding never starts with a zero unless the argument was zero. Negative numbers are preceded by a minus sign. Positive numbers are not preceded by anything.
int16Dec :: Int16 -> Builder Source #
Encodes a signed 16-bit integer as decimal. This encoding never starts with a zero unless the argument was zero. Negative numbers are preceded by a minus sign. Positive numbers are not preceded by anything.
int8Dec :: Int8 -> Builder Source #
Encodes a signed 8-bit integer as decimal. This encoding never starts with a zero unless the argument was zero. Negative numbers are preceded by a minus sign. Positive numbers are not preceded by anything.
intDec :: Int -> Builder Source #
Encodes a signed machine-sized integer as decimal. This encoding never starts with a zero unless the argument was zero. Negative numbers are preceded by a minus sign. Positive numbers are not preceded by anything.
Unsigned Words
64-bit
word64PaddedUpperHex :: Word64 -> Builder Source #
Encode a 64-bit unsigned integer as hexadecimal, zero-padding
the encoding to 16 digits. This uses uppercase for the alphabetical
digits. For example, this encodes the number 1022 as 00000000000003FE
.
32-bit
word32PaddedUpperHex :: Word32 -> Builder Source #
Encode a 32-bit unsigned integer as hexadecimal, zero-padding
the encoding to 8 digits. This uses uppercase for the alphabetical
digits. For example, this encodes the number 1022 as 000003FE
.
16-bit
word16PaddedUpperHex :: Word16 -> Builder Source #
Encode a 16-bit unsigned integer as hexadecimal, zero-padding
the encoding to 4 digits. This uses uppercase for the alphabetical
digits. For example, this encodes the number 1022 as 03FE
.
word16PaddedLowerHex :: Word16 -> Builder Source #
Encode a 16-bit unsigned integer as hexadecimal, zero-padding
the encoding to 4 digits. This uses lowercase for the alphabetical
digits. For example, this encodes the number 1022 as 03fe
.
word16LowerHex :: Word16 -> Builder Source #
Encode a 16-bit unsigned integer as hexadecimal without leading
zeroes. This uses lowercase for the alphabetical digits. For
example, this encodes the number 1022 as 3fe
.
word16UpperHex :: Word16 -> Builder Source #
Encode a 16-bit unsigned integer as hexadecimal without leading
zeroes. This uses uppercase for the alphabetical digits. For
example, this encodes the number 1022 as 3FE
.
8-bit
word8PaddedUpperHex :: Word8 -> Builder Source #
Encode a 8-bit unsigned integer as hexadecimal, zero-padding
the encoding to 2 digits. This uses uppercase for the alphabetical
digits. For example, this encodes the number 11 as 0B
.
word8LowerHex :: Word8 -> Builder Source #
Encode a 16-bit unsigned integer as hexadecimal without leading
zeroes. This uses lowercase for the alphabetical digits. For
example, this encodes the number 1022 as 3FE
.
ascii :: Char -> Builder Source #
Encode an ASCII char. Precondition: Input must be an ASCII character. This is not checked.
Machine-Readable
word64BE :: Word64 -> Builder Source #
Requires exactly 8 bytes. Dump the octets of a 64-bit word in a big-endian fashion.
word32BE :: Word32 -> Builder Source #
Requires exactly 4 bytes. Dump the octets of a 32-bit word in a big-endian fashion.
word16BE :: Word16 -> Builder Source #
Requires exactly 2 bytes. Dump the octets of a 16-bit word in a big-endian fashion.