lsm-tree-0.1.0.0: Log-structured merge-trees
Safe HaskellSafe-Inferred
LanguageGHC2021

Database.LSMTree.Internal.ByteString

Description

bytestring extras

Synopsis

Documentation

tryCheapToShort :: ByteString -> Either String ShortByteString Source #

\( O(1) \) conversion, if possible.

In addition to the conditions explained for tryGetByteArray, the bytestring must use the full length of the underlying byte array.

tryGetByteArray :: ByteString -> Either String (ByteArray, Int) Source #

\( O(1) \) conversion from a strict ByteString to its underlying pinned ByteArray, if possible. Also returns the length (in bytes) of the byte array prefix that was used by the bytestring.

Strict bytestrings are allocated using mallocPlainForeignPtrBytes, so we are expecting a PlainPtr (or FinalPtr when the length is 0). We also require that bytestrings referencing a byte array point point at the beginning, without any offset.

byteArrayToByteString :: Int -> Int -> ByteArray -> ByteString Source #

\( O(1) \) conversion if the byte array is pinned, \( O(n) \) otherwise. Takes offset and length of the slice to be used.

unsafePinnedByteArrayToByteString :: HasCallStack => Int -> Int -> ByteArray -> ByteString Source #

\( O(1) \) conversion. Takes offset and length of the slice to be used. Fails if the byte array is not pinned.

Based on fromShort.