-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an API for the ByteString builder #22
Comments
What kind of API are we talking about? |
The simplest. Something like: prependByteStringBuilder :: Int -> BB.Builder -> Buffer %1 -> Buffer
appendByteStringBuilder :: Buffer %1 -> Int -> BB.Builder -> Buffer where the
Reading the |
I'm not sure that tying us that close to internal details of |
You mean something like: appendBSBuilder :: BB.Builder -> Buffer %1 -> Buffer
appendBSBuilder builder = unsafeDupablePerformIO
(B.unsafeUseAsCString
(BL.toStrict (BB.toLazyByteString builder))
(\(Ptr addr) -> pure (|># addr)))
appendBSBuilder' :: Buffer %1 -> BB.Builder -> Buffer
appendBSBuilder' buf builder = foldlIntoBuffer
(\b bs -> unsafeDupablePerformIO (B.unsafeUseAsCString bs (\(Ptr addr) -> pure (|># addr))) b)
buf
(BL.toChunks (BB.toLazyByteString builder)) This does not look trivial. If we do not provide an API, it would be a good idea to document the best method to implement it. |
Yeah, something like this. Documenting it or maybe even providing helpers similar to ones you just wrote would be nice. |
I just realized that this package uses a
ByteString
builder to implement(|>%)
and(%<|)
.I did play a bit with them in #20, but felt uncomfortable with
unsafePerformIO
, etc. I then tried withData.ByteString.Lazy.foldlChunks
, which obviously would not lead to great perf, giving we need to allocate intermediate chunks and then copy them.Should we provide an API for the
ByteString
builder? It would unlock quite a lot of features.The text was updated successfully, but these errors were encountered: