packages/binary.git
4 years agoBump version to 0.7.3.0 0.7.3.0 binary-0.7.2.3-release
Lennart Kolmodin [Thu, 22 Jan 2015 17:14:21 +0000 (18:14 +0100)] 
Bump version to 0.7.3.0

4 years agoUpdate changelog.md with changes for 0.7.3.0
Lennart Kolmodin [Thu, 22 Jan 2015 17:13:42 +0000 (18:13 +0100)] 
Update changelog.md with changes for 0.7.3.0

4 years agoMerge pull request #66 from JPMoresmau/master
Lennart Kolmodin [Sat, 17 Jan 2015 16:59:35 +0000 (19:59 +0300)] 
Merge pull request #66 from JPMoresmau/master

Fix doc: Int64 are written as 8 bytes, not 4

4 years agoFix doc: Int64 are written as 8 bytes, not 4
JP Moresmau [Sat, 17 Jan 2015 16:55:51 +0000 (17:55 +0100)] 
Fix doc: Int64 are written as 8 bytes, not 4

4 years agoSilence warning.
Lennart Kolmodin [Sat, 10 Jan 2015 09:51:38 +0000 (12:51 +0300)] 
Silence warning.

4 years agoFix compilation error.
Lennart Kolmodin [Thu, 1 Jan 2015 22:33:47 +0000 (01:33 +0300)] 
Fix compilation error.

arbitrarySizedNatural is only defined when base >= 4.8.

4 years agoAdd instance for Natural.
Lennart Kolmodin [Thu, 1 Jan 2015 18:26:18 +0000 (21:26 +0300)] 
Add instance for Natural.

Natural is a new data type that comes with base-4.8 (GHC 7.10).
We serialize it in the same way as we do with Integer.
Since this is a new data type there are some ugly CPPs to handle whether
Natural is there or not.
Serialization tests have been added as well. Since QuickCheck doesn't yet
implement instance Arbitrary Natural we do a workaround here.
This fixes #63.

4 years agoTravis: Use cabal-1.18 for older ghc versions.
Lennart Kolmodin [Sat, 27 Dec 2014 12:34:38 +0000 (15:34 +0300)] 
Travis: Use cabal-1.18 for older ghc versions.

We use the sandbox feature.

4 years agoAdd GHC 7.10 to test matrix
Lennart Kolmodin [Fri, 26 Dec 2014 17:42:14 +0000 (20:42 +0300)] 
Add GHC 7.10 to test matrix

4 years agoBump version to 0.7.2.3
Lennart Kolmodin [Sat, 13 Dec 2014 21:27:45 +0000 (00:27 +0300)] 
Bump version to 0.7.2.3

4 years agoUpdate changelog for 0.7.2.3
Lennart Kolmodin [Sat, 13 Dec 2014 21:26:48 +0000 (00:26 +0300)] 
Update changelog for 0.7.2.3

4 years agoMerge pull request #62 from hvr/pr-binary
Lennart Kolmodin [Sat, 13 Dec 2014 21:13:17 +0000 (00:13 +0300)] 
Merge pull request #62 from hvr/pr-binary

Remove INLINEs from GBinary/GSum methods

4 years agoRemove INLINEs from GBinary/GSum methods
Herbert Valerio Riedel [Thu, 25 Sep 2014 20:07:13 +0000 (22:07 +0200)] 
Remove INLINEs from GBinary/GSum methods

These interact very badly with GHC 7.9.x's simplifier

See also

 - https://ghc.haskell.org/trac/ghc/ticket/9630 and

 - https://ghc.haskell.org/trac/ghc/ticket/9583

4 years agoBump version to 0.7.2.2.
Lennart Kolmodin [Thu, 25 Sep 2014 19:06:34 +0000 (23:06 +0400)] 
Bump version to 0.7.2.2.

4 years agoMerge pull request #59 from hvr/pr-ghc-base
Lennart Kolmodin [Thu, 25 Sep 2014 18:46:18 +0000 (22:46 +0400)] 
Merge pull request #59 from hvr/pr-ghc-base

Use explicit import-list for `GHC.Base` import

4 years agoAdd -fno-spec-constr when building on Travis CI.
Lennart Kolmodin [Thu, 25 Sep 2014 16:47:03 +0000 (20:47 +0400)] 
Add -fno-spec-constr when building on Travis CI.

It should save a lot of memory, and hopefully make the builds
succeed more often.

4 years agoConditionally instantiate NFData depending on bytestring version.
Lennart Kolmodin [Thu, 25 Sep 2014 13:21:26 +0000 (17:21 +0400)] 
Conditionally instantiate NFData depending on bytestring version.

Should fix #61.

4 years agoGHC < 7.6 fails when hiding a function that doesn't exists.
Lennart Kolmodin [Thu, 25 Sep 2014 12:17:29 +0000 (16:17 +0400)] 
GHC < 7.6 fails when hiding a function that doesn't exists.

4 years agoIn Travis CI, ghc 7.8.2 -> 7.8.3.
Lennart Kolmodin [Thu, 25 Sep 2014 11:52:41 +0000 (15:52 +0400)] 
In Travis CI, ghc 7.8.2 -> 7.8.3.

4 years agoFix compilation issue with criterion-1.
Lennart Kolmodin [Thu, 25 Sep 2014 11:49:53 +0000 (15:49 +0400)] 
Fix compilation issue with criterion-1.

4 years agoUse explicit import-list for `GHC.Base` import
Herbert Valerio Riedel [Wed, 17 Sep 2014 20:48:38 +0000 (22:48 +0200)] 
Use explicit import-list for `GHC.Base` import

`base` is currently being restructured in GHC HEAD which will very likely
break this unqualified `GHC.Base` import. So this simple change will make
that import statement future-proof.

5 years agoSimplify the shrinking of Action in QC tests.
Lennart Kolmodin [Thu, 17 Jul 2014 11:10:43 +0000 (15:10 +0400)] 
Simplify the shrinking of Action in QC tests.

5 years agoBump version to 0.7.2.1.
Lennart Kolmodin [Sun, 18 May 2014 09:04:06 +0000 (13:04 +0400)] 
Bump version to 0.7.2.1.

Also update changelog.

5 years agoFix to compile with GHC 6.10.4
Lennart Kolmodin [Sun, 18 May 2014 08:58:33 +0000 (12:58 +0400)] 
Fix to compile with GHC 6.10.4

Before base-4.2.0.0 Alternative didn't define 'many' and 'some'.
Use conditional to exclude those definitions on GHC < 6.12.1.

This issue was reported in issue #55.

5 years agoImprove Travis integration.
Lennart Kolmodin [Sun, 11 May 2014 17:46:21 +0000 (21:46 +0400)] 
Improve Travis integration.

5 years agoUpdate changelog.md with changes of 0.7.2.0.
Lennart Kolmodin [Sun, 11 May 2014 12:29:40 +0000 (16:29 +0400)] 
Update changelog.md with changes of 0.7.2.0.

5 years agoUpdate README's example about deriving instances
Lennart Kolmodin [Sun, 11 May 2014 12:13:00 +0000 (16:13 +0400)] 
Update README's example about deriving instances

Demonstrate how to use GHC's Generics.

5 years agoAdd Travis CI build status image to the README
Lennart Kolmodin [Sun, 11 May 2014 12:05:28 +0000 (16:05 +0400)] 
Add Travis CI build status image to the README

5 years agoLink to contributors.
Lennart Kolmodin [Sun, 11 May 2014 11:24:42 +0000 (15:24 +0400)] 
Link to contributors.

5 years agoFirst attempt at adding Travis CI support.
Lennart Kolmodin [Sun, 11 May 2014 11:09:42 +0000 (15:09 +0400)] 
First attempt at adding Travis CI support.

5 years agoVersion bump to 0.7.2.0
Lennart Kolmodin [Sun, 11 May 2014 11:08:50 +0000 (15:08 +0400)] 
Version bump to 0.7.2.0

5 years agoUpdate .gitignore and .hgignore with cabal sandbox files
Lennart Kolmodin [Sun, 11 May 2014 11:06:37 +0000 (15:06 +0400)] 
Update .gitignore and .hgignore with cabal sandbox files

5 years agobinary.cabal: update list with which GHCs we've tested
Lennart Kolmodin [Sun, 11 May 2014 11:02:35 +0000 (15:02 +0400)] 
binary.cabal: update list with which GHCs we've tested

5 years agoIn test-suites and benchmarks, depend on source
Lennart Kolmodin [Sun, 11 May 2014 11:00:31 +0000 (15:00 +0400)] 
In test-suites and benchmarks, depend on source

Depend directly on the source of binary, instead of the library itself.
This is unfortunate as it complicates the cabal file, but we have to in
order to remove circular dependencies when installing dependencies of
the test-suites and benchmarks.

5 years agoBug fix isolate; keep labels from within failing isolate
Lennart Kolmodin [Sun, 11 May 2014 09:24:01 +0000 (13:24 +0400)] 
Bug fix isolate; keep labels from within failing isolate

When an isolated decoder failed due to over consuming input, any
labels set within that decoder were lost since demanding
more input would fail within the isolate-decoder runner and not in
the isolated decoder itself.
With this change the signal of lack of more input is passed
into the isolated decoder which in turn will fail, keeping any
labels up to that point.

5 years agoBug fix isolate; use correct offset in error message
Lennart Kolmodin [Sun, 11 May 2014 09:22:12 +0000 (13:22 +0400)] 
Bug fix isolate; use correct offset in error message

When a isolate decoder fails, it includes information about the
offsets of how far in the decoding it got in the error message.
With this change the offset is now correct.

5 years agoBug fix isolate; decoder must use all input
Lennart Kolmodin [Sun, 11 May 2014 09:20:12 +0000 (13:20 +0400)] 
Bug fix isolate; decoder must use all input

A decoder could have been given the final chuck, but not used
all its input, and still succeed.
This change corrects the behavior and makes sure that isolate
must use all input in order to succeed.

5 years agoImprove model tests
Lennart Kolmodin [Sun, 11 May 2014 09:16:57 +0000 (13:16 +0400)] 
Improve model tests

In the model tests, generate more kinds of programs.
Previously, only programs that failed by using 'fail' were generated.
Now we also fail decoders by running out of input, using too much or
too little input in a isolate block.
Also correct the tests when they check for labels.

This change exposes some bugs in isolate.

5 years agoMerge pull request #54 from jstolarek/T8883
Lennart Kolmodin [Fri, 25 Apr 2014 05:38:12 +0000 (09:38 +0400)] 
Merge pull request #54 from jstolarek/T8883

Add LANGUAGE extensions for inferred signatures.

5 years agoAdd LANGUAGE extensions for inferred signatures.
Jan Stolarek [Sat, 19 Apr 2014 07:04:02 +0000 (09:04 +0200)] 
Add LANGUAGE extensions for inferred signatures.

Some of the inferred signatures required LANGUAGE extensions that
were not enabled. Since now GHC checks that we have to explicitly
list required extensions.

5 years agoMake tests compile on GHC 7.4.1.
Lennart Kolmodin [Sat, 19 Apr 2014 07:13:38 +0000 (11:13 +0400)] 
Make tests compile on GHC 7.4.1.

5 years agoUpdate changelog.
Lennart Kolmodin [Sat, 19 Apr 2014 07:09:07 +0000 (11:09 +0400)] 
Update changelog.

5 years agoAdd function 'isolate'.
Lennart Kolmodin [Mon, 14 Apr 2014 19:10:53 +0000 (23:10 +0400)] 
Add function 'isolate'.

isolate :: Int -> Get a -> Get a
Isolates a decoder to a fixed number of bytes.

5 years agoMerge branch 'isolate' of github.com:singpolyma/binary into singpolyma-isolate
Lennart Kolmodin [Wed, 2 Apr 2014 20:21:04 +0000 (00:21 +0400)] 
Merge branch 'isolate' of github.com:singpolyma/binary into singpolyma-isolate

5 years agoAdd changelog.md
Lennart Kolmodin [Sun, 30 Mar 2014 13:31:26 +0000 (17:31 +0400)] 
Add changelog.md

5 years agoAdd test to check error position and remaining input.
Lennart Kolmodin [Sun, 23 Mar 2014 16:54:08 +0000 (20:54 +0400)] 
Add test to check error position and remaining input.

5 years agoLabel test samples in prop_label.
Lennart Kolmodin [Sun, 23 Mar 2014 06:26:29 +0000 (10:26 +0400)] 
Label test samples in prop_label.

5 years agoRemove commented out code, and style imports.
Lennart Kolmodin [Thu, 20 Mar 2014 18:26:41 +0000 (22:26 +0400)] 
Remove commented out code, and style imports.

5 years agoAdd function 'label'.
Lennart Kolmodin [Thu, 20 Mar 2014 18:11:39 +0000 (22:11 +0400)] 
Add function 'label'.

'label :: String -> Get a -> Get a' adds the given string to
the error message string if the given decoder fails.
Fixes #16.

5 years agoMerge pull request #48 from lennart/master
Lennart Kolmodin [Sat, 15 Mar 2014 06:49:38 +0000 (09:49 +0300)] 
Merge pull request #48 from lennart/master

[fix] preprocessor errors on clang ghc 7.6.3

5 years ago[fix] preprocessor errors on clang ghc 7.6.3
Lennart Melzer [Thu, 27 Feb 2014 22:35:12 +0000 (23:35 +0100)] 
[fix] preprocessor errors on clang ghc 7.6.3

5 years agoCode block indicators must be indented.
Lennart Kolmodin [Wed, 13 Nov 2013 04:58:05 +0000 (08:58 +0400)] 
Code block indicators must be indented.

Or GHC will barf.

5 years agoRemove indentation of sample code in haddock.
Lennart Kolmodin [Tue, 12 Nov 2013 19:15:38 +0000 (23:15 +0400)] 
Remove indentation of sample code in haddock.

The rendered layout breaks when a code segment has multiple functions,
it renders without the given indentation. In this commit we set the
base indentation to 0 spaces, and thus it renders correctly.

5 years agoAdd haddock annotation, clarify some documentation.
Lennart Kolmodin [Tue, 12 Nov 2013 19:05:27 +0000 (23:05 +0400)] 
Add haddock annotation, clarify some documentation.

5 years agoTypo.
Mikhail Glushenkov [Tue, 12 Nov 2013 02:11:14 +0000 (03:11 +0100)] 
Typo.

5 years agoUpdate the example that uses 'runGetState' to new API.
Mikhail Glushenkov [Tue, 12 Nov 2013 01:51:13 +0000 (02:51 +0100)] 
Update the example that uses 'runGetState' to new API.

Fixes #30.

5 years agoWhitespace.
Mikhail Glushenkov [Tue, 12 Nov 2013 01:47:16 +0000 (02:47 +0100)] 
Whitespace.

5 years agoTypo.
Mikhail Glushenkov [Tue, 12 Nov 2013 01:13:19 +0000 (02:13 +0100)] 
Typo.

5 years agoMerge pull request #38 from edsko/look-ahead-indep-of-chunking
Lennart Kolmodin [Tue, 17 Sep 2013 18:59:58 +0000 (11:59 -0700)] 
Merge pull request #38 from edsko/look-ahead-indep-of-chunking

Test that look-ahead is independent of chunking

5 years agoTest that look-ahead is independent of chunking
Edsko de Vries [Tue, 17 Sep 2013 13:21:52 +0000 (14:21 +0100)] 
Test that look-ahead is independent of chunking

5 years agoImplement `isolate` for reading fixed-size blocks.
Stephen Paul Weber [Tue, 10 Sep 2013 23:14:05 +0000 (18:14 -0500)] 
Implement `isolate` for reading fixed-size blocks.

Closes #32

6 years agoVersion bump to 0.7.1.0. binary-0.7.1.0-release
Lennart Kolmodin [Wed, 1 May 2013 16:57:15 +0000 (20:57 +0400)] 
Version bump to 0.7.1.0.

6 years agoDepend on test-framework-quickcheck2 >= 0.3
Lennart Kolmodin [Sat, 20 Apr 2013 09:56:16 +0000 (13:56 +0400)] 
Depend on test-framework-quickcheck2 >= 0.3

test-framework-quickcheck2 depends on QC < 2.6 (even though it works
with QC 2.6...).
This workaround makes cabal pick an older version of QC.

6 years agoUpdates to the README.
Lennart Kolmodin [Sat, 20 Apr 2013 09:33:21 +0000 (13:33 +0400)] 
Updates to the README.

How to build, and why you probably don't need to.

6 years agoReimplement lookAheadE
Lennart Kolmodin [Sat, 20 Apr 2013 07:11:15 +0000 (11:11 +0400)] 
Reimplement lookAheadE

Including tests.

6 years agoUpdate binary.cabal about README.md's new name.
Lennart Kolmodin [Wed, 17 Apr 2013 06:02:49 +0000 (10:02 +0400)] 
Update binary.cabal about README.md's new name.

6 years agoMinor fixes to the README.
Lennart Kolmodin [Wed, 17 Apr 2013 05:47:25 +0000 (09:47 +0400)] 
Minor fixes to the README.

6 years agoFixed a typo.
Daniel Díaz [Wed, 17 Apr 2013 00:28:14 +0000 (21:28 -0300)] 
Fixed a typo.

6 years agoREADME: Added info about a binary instance example.
Daniel Díaz [Wed, 17 Apr 2013 00:27:09 +0000 (21:27 -0300)] 
README: Added info about a binary instance example.

6 years agoREADME updated with markdown format.
Daniel Díaz [Wed, 17 Apr 2013 00:24:03 +0000 (21:24 -0300)] 
README updated with markdown format.

The README now follows the markdown format, suitable to display in the GitHub repository site. Also, the documentation in this file has been slightly extended.

6 years agoAdded .md extension to README file
Daniel Díaz [Wed, 17 Apr 2013 00:11:44 +0000 (21:11 -0300)] 
Added .md extension to README file

6 years agoAdded MonadPlus instance.
Daniel Diaz [Tue, 16 Apr 2013 02:53:29 +0000 (22:53 -0400)] 
Added MonadPlus instance.

6 years agoAdd a Cereal bracket test.
Lennart Kolmodin [Tue, 5 Mar 2013 11:48:33 +0000 (15:48 +0400)] 
Add a Cereal bracket test.

6 years agoTypo.
Lennart Kolmodin [Sat, 2 Mar 2013 14:54:47 +0000 (18:54 +0400)] 
Typo.

6 years agoBump to 0.7.0.1
Lennart Kolmodin [Sat, 2 Mar 2013 07:52:46 +0000 (11:52 +0400)] 
Bump to 0.7.0.1

6 years agoFix code examples in documentation.
Lennart Kolmodin [Fri, 1 Mar 2013 21:27:35 +0000 (01:27 +0400)] 
Fix code examples in documentation.

The old name runGetPartial was used instead of runGetIncremental.

6 years agoBump to 0.7.0.0
Lennart Kolmodin [Fri, 1 Mar 2013 09:32:16 +0000 (13:32 +0400)] 
Bump to 0.7.0.0

6 years agoOnly run bracket bench on 100kb of brackets.
Lennart Kolmodin [Fri, 1 Mar 2013 05:37:11 +0000 (09:37 +0400)] 
Only run bracket bench on 100kb of brackets.

6 years agoFix the benchmark.
Lennart Kolmodin [Thu, 28 Feb 2013 19:11:49 +0000 (23:11 +0400)] 
Fix the benchmark.

Broke it during the "cleanup"...

6 years agoSpecial case when we pushBack an empty list.
Lennart Kolmodin [Thu, 28 Feb 2013 15:57:26 +0000 (19:57 +0400)] 
Special case when we pushBack an empty list.

Gives about 10% speedup for the <|> of many chunks.

6 years agoClean up <|> benchmark.
Lennart Kolmodin [Thu, 28 Feb 2013 15:48:21 +0000 (19:48 +0400)] 
Clean up <|> benchmark.

Also add attoparsec to do the same <|> benchmark.
For attoparsec, we bench with a strict bytestring,
with a lazy bytestring with only one chunk, and a
lazy bytestring with many chunks.

6 years agoAdd module documentation for Data.Binary.Get.
Lennart Kolmodin [Sun, 24 Feb 2013 11:12:59 +0000 (15:12 +0400)] 
Add module documentation for Data.Binary.Get.

Issue #15.

6 years agoMore documentation.
Lennart Kolmodin [Sat, 23 Feb 2013 16:46:27 +0000 (20:46 +0400)] 
More documentation.

Issue #15.

6 years agoAdd all files to binary.cabal
Lennart Kolmodin [Sat, 23 Feb 2013 10:00:57 +0000 (14:00 +0400)] 
Add all files to binary.cabal

Makes 'cabal sdist' work as intended.

6 years agoRemove ancient TODO
Lennart Kolmodin [Sat, 23 Feb 2013 09:36:35 +0000 (13:36 +0400)] 
Remove ancient TODO

6 years agoUpdate Don Stewart's email address.
Lennart Kolmodin [Thu, 21 Feb 2013 08:03:47 +0000 (12:03 +0400)] 
Update Don Stewart's email address.

6 years agoUpdate benchmark. Add cereal and attoparsec for comparison.
Lennart Kolmodin [Wed, 20 Feb 2013 09:12:39 +0000 (13:12 +0400)] 
Update benchmark. Add cereal and attoparsec for comparison.

6 years agoFunction haddocks for lookAhead and lookAheadM.
Lennart Kolmodin [Mon, 18 Feb 2013 20:08:16 +0000 (00:08 +0400)] 
Function haddocks for lookAhead and lookAheadM.

Issue #17.

6 years agoSilent warning.
Lennart Kolmodin [Mon, 18 Feb 2013 12:03:11 +0000 (16:03 +0400)] 
Silent warning.

6 years agoModel test: provide better shrinking.
Lennart Kolmodin [Mon, 18 Feb 2013 08:08:41 +0000 (12:08 +0400)] 
Model test: provide better shrinking.

The model now has a constructor Actions which holds a list of Action.
It can be used to unpack a LookAhead(M) or Try in order to shrink the program.

6 years agoCleanup instance Arbitrary of lazy bytestrings.
Lennart Kolmodin [Sun, 17 Feb 2013 19:38:13 +0000 (23:38 +0400)] 
Cleanup instance Arbitrary of lazy bytestrings.

6 years agoImplement lookAheadM.
Lennart Kolmodin [Sun, 17 Feb 2013 19:37:07 +0000 (23:37 +0400)] 
Implement lookAheadM.

Also with tests.

6 years agoCompile QC tests with -O2.
Lennart Kolmodin [Sun, 17 Feb 2013 16:55:43 +0000 (20:55 +0400)] 
Compile QC tests with -O2.

6 years agoModel test: make sure decoded data is as expected (not only offset).
Lennart Kolmodin [Sun, 17 Feb 2013 16:54:06 +0000 (20:54 +0400)] 
Model test: make sure decoded data is as expected (not only offset).

Previously we tracked only byte positions in the model, and compared
with the decoders' offset (via bytesRead).
Now we give the whole input to the evaluator, and thanks to that we track
offset we can easily also compare that the decoded data is what we expect.

6 years agoImplement <|> using runAndKeepTrack.
Lennart Kolmodin [Sun, 17 Feb 2013 12:47:54 +0000 (16:47 +0400)] 
Implement <|> using runAndKeepTrack.

6 years agoAdd .cabal-sandbox to .gitignore.
Lennart Kolmodin [Sat, 16 Feb 2013 15:54:31 +0000 (19:54 +0400)] 
Add .cabal-sandbox to .gitignore.

6 years agoImplement lookAhead.
Lennart Kolmodin [Sat, 16 Feb 2013 08:10:22 +0000 (12:10 +0400)] 
Implement lookAhead.

Issue #17. Test present, documentation still missing.
This function was removed with the 0.6.* branch, and had quite few users.
The plan was to use <|> instead, but lookAhead was missed since it
offers some functionality that <|> cannot provide without larger restructuring of the application.
lookAhead can be implemented in binary without affecting any other functionality,
so here it is again.

This also makes 0.6.* more backwards compatible with earlier versions,
this saving the developer from #if MIN_VERSION hacks.

6 years agoAdd test for encodeFile and decodeFile.
Lennart Kolmodin [Fri, 15 Feb 2013 20:17:40 +0000 (00:17 +0400)] 
Add test for encodeFile and decodeFile.

Issue #22.

6 years agoDocs for decodeFile and decodeFileOrFail.
Lennart Kolmodin [Fri, 15 Feb 2013 18:12:21 +0000 (22:12 +0400)] 
Docs for decodeFile and decodeFileOrFail.

Issue #22.

6 years agoAdd decodeOrFail and decodeFileOrFail.
Lennart Kolmodin [Fri, 15 Feb 2013 11:19:18 +0000 (15:19 +0400)] 
Add decodeOrFail and decodeFileOrFail.

Issue #22. Documentation and tests still missing.
Rewrote decodeFile* to use chunk pushing style.
This code currently uses Data.ByteString.Lazy.Internal.defaultChunkSize
when reading from handles. I'd prefer to be more independent
of bytestring's internals, let's copy the code to this module.