Add shortByteString builder. Prepare the changelog for a major release.

This commit is contained in:
Andrew Martin 2019-10-17 09:45:08 -04:00
parent 691749e27a
commit a66f8e1200
2 changed files with 16 additions and 3 deletions

View file

@ -1,15 +1,22 @@
# Revision history for small-bytearray-builder # 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 * Breaking change: Change the internal implementation of `Builder`. This
that require prefixing a payload with its length. 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 `int{16,32,64}BE` and `int{16,32,64LE}` as conveniences.
* Add little-endian encoding functions for `Word16`, `Word32`, and `Word64`. * Add little-endian encoding functions for `Word16`, `Word32`, and `Word64`.
* Add big-endian and little-endian functions for copying a * Add big-endian and little-endian functions for copying a
`PrimArray` of numbers (both signed and unsigned) into a builder. `PrimArray` of numbers (both signed and unsigned) into a builder.
* Add `flush`, `copy`, and `insert` for better control when * Add `flush`, `copy`, and `insert` for better control when
converting byte sequences to builders. converting byte sequences to builders.
* Add `shortByteString` to improve interoperability with the
`bytestring` library.
## 0.2.1.0 -- 2019-09-05 ## 0.2.1.0 -- 2019-09-05

View file

@ -18,6 +18,7 @@ module Data.ByteArray.Builder
, copy , copy
, insert , insert
, byteArray , byteArray
, shortByteString
, shortTextUtf8 , shortTextUtf8
, shortTextJsonString , shortTextJsonString
, cstring , cstring
@ -184,6 +185,11 @@ fromBoundedOne (UnsafeBounded.Builder f) = Builder $ \buf0 off0 len0 cs0 s0 ->
byteArray :: ByteArray -> Builder byteArray :: ByteArray -> Builder
byteArray a = bytes (Bytes a 0 (PM.sizeofByteArray a)) 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 -- | Create a builder from a sliced byte sequence. The variants
-- 'copy' and 'insert' provide more control over whether or not -- 'copy' and 'insert' provide more control over whether or not
-- the byte sequence is copied or aliased. This function is preferred -- the byte sequence is copied or aliased. This function is preferred