ptr-poker-0.1.2.6: Pointer poking action construction and composition toolkit
Safe HaskellNone
LanguageHaskell2010

PtrPoker.Write

Synopsis

Documentation

writeToByteString :: Write -> ByteString Source #

Execute Write, producing strict ByteString.

data Write Source #

Specification of how many bytes to allocate and how to populate them.

Useful for creating strict bytestrings and tasks like that.

Constructors

Write 

Fields

Instances

Instances details
IsString Write Source #

Reuses the IsString instance of ByteString.

Instance details

Defined in PtrPoker.Write

Methods

fromString :: String -> Write #

Semigroup Write Source # 
Instance details

Defined in PtrPoker.Write

Methods

(<>) :: Write -> Write -> Write #

sconcat :: NonEmpty Write -> Write #

stimes :: Integral b => b -> Write -> Write #

Monoid Write Source # 
Instance details

Defined in PtrPoker.Write

Methods

mempty :: Write #

mappend :: Write -> Write -> Write #

mconcat :: [Write] -> Write #

concat :: Foldable f => f Write -> Write Source #

Concatenate a foldable of writes.

word8 :: Word8 -> Write Source #

Render Word8 as byte.

lWord16 :: Word16 -> Write Source #

Render Word16 in Little-endian.

bWord16 :: Word16 -> Write Source #

Render Word16 in Big-endian.

lWord32 :: Word32 -> Write Source #

Render Word32 in Little-endian.

bWord32 :: Word32 -> Write Source #

Render Word32 in Big-endian.

lWord64 :: Word64 -> Write Source #

Render Word64 in Little-endian.

bWord64 :: Word64 -> Write Source #

Render Word64 in Big-endian.

lInt16 :: Int16 -> Write Source #

Render Int16 in Little-endian.

bInt16 :: Int16 -> Write Source #

Render Int16 in Big-endian.

lInt32 :: Int32 -> Write Source #

Render Int32 in Little-endian.

bInt32 :: Int32 -> Write Source #

Render Int32 in Big-endian.

lInt64 :: Int64 -> Write Source #

Render Int64 in Little-endian.

bInt64 :: Int64 -> Write Source #

Render Int64 in Big-endian.

word64AsciiDec :: Word64 -> Write Source #

Render Word64 in ASCII decimal.

wordAsciiDec :: Word -> Write Source #

Render Word in ASCII decimal.

int64AsciiDec :: Int64 -> Write Source #

Render Int64 in ASCII decimal.

intAsciiDec :: Int -> Write Source #

Render Int in ASCII decimal.

doubleAsciiDec :: Double -> Write Source #

Render double interpreting non-real values, such as NaN, Infinity, -Infinity, as is.

zeroNonRealDoubleAsciiDec :: Double -> Write Source #

Render double interpreting non real values, such as NaN, Infinity, -Infinity, as zero.

scientificAsciiDec :: Scientific -> Write Source #

Render Scientific in ASCII decimal.

byteString :: ByteString -> Write Source #

Efficiently copy the contents of ByteString using memcpy.

textUtf8 :: Text -> Write Source #

Render Text in UTF8.

Does pretty much the same as encodeUtf8, both implementation and performance-wise, while allowing you to avoid redundant memcpy compared to (byteString . encodeUtf8).

Following are the benchmark results comparing the performance of (writeToByteString . textUtf8) with Data.Text.Encoding.encodeUtf8 on inputs in Latin and Greek (requiring different number of surrogate bytes). The results show that they are quite similar.

Benchmark results

Expand
textUtf8/ptr-poker/latin/1               mean 51.54 ns  ( +- 3.083 ns  )
textUtf8/ptr-poker/latin/10              mean 132.8 ns  ( +- 14.75 ns  )
textUtf8/ptr-poker/latin/100             mean 860.6 ns  ( +- 66.61 ns  )
textUtf8/ptr-poker/greek/1               mean 106.4 ns  ( +- 19.28 ns  )
textUtf8/ptr-poker/greek/10              mean 498.4 ns  ( +- 8.022 ns  )
textUtf8/ptr-poker/greek/100             mean 4.462 μs  ( +- 31.58 ns  )
textUtf8/text/latin/1                    mean 52.77 ns  ( +- 3.311 ns  )
textUtf8/text/latin/10                   mean 206.1 ns  ( +- 26.78 ns  )
textUtf8/text/latin/100                  mean 1.337 μs  ( +- 43.34 ns  )
textUtf8/text/greek/1                    mean 88.22 ns  ( +- 1.119 ns  )
textUtf8/text/greek/10                   mean 475.2 ns  ( +- 21.15 ns  )
textUtf8/text/greek/100                  mean 4.252 μs  ( +- 64.33 ns  )