bit-protocol: Encode binary protocols with some odd bit numbers into a bytestring

[ bits, bsd3, bytes, data, library, parsing, protocols ] [ Propose Tags ] [ Report a vulnerability ]

Encode binary protocols with some odd bit numbers into a bytestring.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.2.1.0, 0.2.2.0, 0.2.3.0
Dependencies base (>=4.7 && <5), base64-bytestring, bytestring, dlist, ghc-prim [details]
License BSD-3-Clause
Copyright Kostiantyn Rybnikov
Author Kostiantyn Rybnikov
Maintainer k-bx@k-bx.com
Category Data, Parsing, Bits, Bytes, Protocols
Home page https://github.com/k-bx/bit-protocol#readme
Uploaded by k_bx at 2018-07-26T13:07:08Z
Distributions NixOS:0.2.3.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3057 total (3 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-07-26 [all 1 reports]

Readme for bit-protocol-0.1.0.0

[back to package description]

bit-protocol

A package suitable for binary protocols defined in a manner where you have bit counts not aligned by 8.

For example, if you have a protocol for sending user profiles saying:

The value sent must be a base64url-encoded string consisting of four values:

  • 6 bits representing user's age
  • 7 bits for their favorite number
  • 5 bits for their lucky number
  • 6 bits for a random number

you could use the library as follows:

import Data.BitProtocol import Data.ByteString.Base64.URL (encode) main :: IO () main = do let age = 29 fav = 12 lucky = 13 rand = 14 -- the number in protocol should be base64url(011101_0001100_01101_001110) print $ encode $ bitsValsToBS8 $ [BitsVal 6 age, BitsVal 7 fav, BitsVal 5 lucky, BitsVal 6 rand] -- will output "dGNO" -- which is the same as `encode (BC8.pack (map chr [0b01110100, 0b01100011, 0b01001110]))`