Add cstring#

This commit is contained in:
Andrew Martin 2021-06-29 14:47:44 -04:00
parent a51dcb65b6
commit 2e279c62f2
2 changed files with 7 additions and 1 deletions

View file

@ -9,6 +9,7 @@ to ease the migration process.
* Fix `doubleDec`, which was encoding small numbers incorrectly. * Fix `doubleDec`, which was encoding small numbers incorrectly.
* Add `runByteString` for producing `ByteString` from bounded builders. * Add `runByteString` for producing `ByteString` from bounded builders.
* Add `cstring#` for producing builder from `Addr#`.
* Correct the required length calculation for json string encoding. * Correct the required length calculation for json string encoding.
## 0.3.7.0 -- 2020-11-06 ## 0.3.7.0 -- 2020-11-06

View file

@ -29,6 +29,7 @@ module Data.Bytes.Builder
, shortTextUtf8 , shortTextUtf8
, shortTextJsonString , shortTextJsonString
, cstring , cstring
, cstring#
, cstringLen , cstringLen
, stringUtf8 , stringUtf8
-- * Encode Integral Types -- * Encode Integral Types
@ -153,7 +154,7 @@ import Foreign.C.String (CStringLen)
import GHC.ByteOrder (ByteOrder(BigEndian,LittleEndian),targetByteOrder) import GHC.ByteOrder (ByteOrder(BigEndian,LittleEndian),targetByteOrder)
import GHC.Exts (Int(I#),Char(C#),Int#,State#,ByteArray#,(>=#)) import GHC.Exts (Int(I#),Char(C#),Int#,State#,ByteArray#,(>=#))
import GHC.Exts (RealWorld,(+#),(-#),(<#)) import GHC.Exts (RealWorld,(+#),(-#),(<#))
import GHC.Exts ((*#)) import GHC.Exts (Addr#,(*#))
import GHC.Integer.Logarithms.Compat (integerLog2#) import GHC.Integer.Logarithms.Compat (integerLog2#)
import GHC.IO (IO(IO),stToIO) import GHC.IO (IO(IO),stToIO)
import GHC.Natural (naturalFromInteger,naturalToInteger) import GHC.Natural (naturalFromInteger,naturalToInteger)
@ -391,6 +392,10 @@ copy (Bytes (ByteArray src# ) (I# soff# ) (I# slen# )) = Builder
where where
!(I# newSz) = max (I# slen#) 4080 !(I# newSz) = max (I# slen#) 4080
cstring# :: Addr# -> Builder
{-# inline cstring# #-}
cstring# x = cstring (Exts.Ptr x)
-- | Create a builder from a C string with explicit length. The builder -- | Create a builder from a C string with explicit length. The builder
-- must be executed before the C string is freed. -- must be executed before the C string is freed.
cstringLen :: CStringLen -> Builder cstringLen :: CStringLen -> Builder