From a66f8e1200db64d2cae1cd1495174ef458c1f39b Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Thu, 17 Oct 2019 09:45:08 -0400 Subject: [PATCH] Add shortByteString builder. Prepare the changelog for a major release. --- CHANGELOG.md | 13 ++++++++++--- src/Data/ByteArray/Builder.hs | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e37cb0f..6895211 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,22 @@ # Revision history for small-bytearray-builder -## 0.3.0.0 -- 2019-??-?? +## 0.3.0.0 -- 2019-10-17 -* Introduce `consLensBE32` for efficient serialization of wire protocols - that require prefixing a payload with its length. +* Breaking change: Change the internal implementation of `Builder`. This + now works a lot more like the builder from `bytestring`. It accumulates + chunks and can do a zero-copy appends when working with a sufficiently + large immutable chunk. This introduces a mild performance regression + (around 10%), but it makes the libary more generally useful. +* Introduce `consLengthBE32` and `consLength64BE` for efficient serialization + of wire protocols that require prefixing a payload with its length. * Add `int{16,32,64}BE` and `int{16,32,64LE}` as conveniences. * Add little-endian encoding functions for `Word16`, `Word32`, and `Word64`. * Add big-endian and little-endian functions for copying a `PrimArray` of numbers (both signed and unsigned) into a builder. * Add `flush`, `copy`, and `insert` for better control when converting byte sequences to builders. +* Add `shortByteString` to improve interoperability with the + `bytestring` library. ## 0.2.1.0 -- 2019-09-05 diff --git a/src/Data/ByteArray/Builder.hs b/src/Data/ByteArray/Builder.hs index dc27796..558ecee 100644 --- a/src/Data/ByteArray/Builder.hs +++ b/src/Data/ByteArray/Builder.hs @@ -18,6 +18,7 @@ module Data.ByteArray.Builder , copy , insert , byteArray + , shortByteString , shortTextUtf8 , shortTextJsonString , cstring @@ -184,6 +185,11 @@ fromBoundedOne (UnsafeBounded.Builder f) = Builder $ \buf0 off0 len0 cs0 s0 -> byteArray :: ByteArray -> Builder byteArray a = bytes (Bytes a 0 (PM.sizeofByteArray a)) +-- | Create a builder from a short bytestring. +shortByteString :: ShortByteString -> Builder +shortByteString (SBS x) = bytes (Bytes a 0 (PM.sizeofByteArray a)) + where a = ByteArray x + -- | Create a builder from a sliced byte sequence. The variants -- 'copy' and 'insert' provide more control over whether or not -- the byte sequence is copied or aliased. This function is preferred