basesystems: Implements encoders/decoders for basesystems

[ bsd3, data, library, numeric, serialization ] [ Propose Tags ] [ Report a vulnerability ]

This package implements encoder and decoder methods for numeric basesystems and provides definitions for common basesystems like base16, base58btc, base64, and more.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
ci

CI Build options

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0.0.0, 1.0.0.1, 1.1.0.0, 1.2.0.0, 1.2.0.1
Change log CHANGELOG.md
Dependencies array (>=0.5 && <0.6), base (>=4.18 && <5), bytestring (>=0.12 && <0.13), containers (>=0.7 && <8), text (>=2.1 && <2.2), xcodec (>=2.0 && <2.1) [details]
Tested with ghc ==9.6.7
License BSD-3-Clause
Author Zoey McBride
Maintainer zoeymcbride@mailbox.org
Uploaded by z0 at 2026-07-21T14:38:57Z
Category Numeric, Data, Serialization
Source repo head: git clone https://git.sr.ht/~z0/basesystems
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 48 total (17 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for basesystems-1.2.0.1

[back to package description]

basesystems hackage.haskell.orgbuilds.sr.ht status

This project contains code for encoding/decoding numeric basesystems in Haskell. It's implemented for the Haskell bytestring types and provides a type-class interface:

class BaseSystem a where
  encoder :: a -> ShortByteString -> String
  decoder :: a -> String -> Maybe ShortByteString

The library creates more BaseSystem classes with methods on normal ByteString in Data.BaseSystem.Strict and LazyByteString in Data.BaseSystem.Lazy. See the example.

Coverage

This project aims to implement the multibase specification's basesystems list.

Currently, the following basesystems are supported:

  • base2 for binary
  • base10 for decimal
  • base16upper and base16lower for hexadecimal
  • base32upper and base32lower for base32
  • base32upperNP and base32lowerNP for base32, without padding
  • base32hexupper and base32hexlower for hex-style base32
  • base32hexupperNP and base32hexlowerNP for hex-style base32, without padding
  • base58btc for Bitcoin's base58
  • base64 and base64url for base64 variants
  • base64NP and base64urlNP for base64 variants, without padding

Example

For an example of using basesystems, we can do the following in GHCI:

Set OverloadedStrings so Strings can act as Text data and import the needed functions. Then import the basesystem functions and packValue from XCodec.Transcoder to convert a number value directly into bytes.

This shows how we can take the binary value of 123 and display it in various number systems:

λ> import Data.BaseSystem (encoder, decoder, base2, base10, base16lower, base32lower)
λ> import XCodec.Transcoder (packValue)
λ> :t encoder
encoder :: BaseSystem a => a -> ShortByteString -> Text
λ> :t decoder
decoder :: BaseSystem a => a -> Text -> Maybe ShortByteString
λ> encoder base2 $ packValue (123 :: Int)
"1111011"
λ> encoder base16lower $ packValue (123 :: Int)
"7b"
λ> encoder base32lower $ packValue (123 :: Int)
"pm======"

We can also use encoders and decoders to translate one numeric representation to another:

λ> encoder base10 <$> decoder base2 "1111011"
Just "123"
λ> encoder base10 <$> decoder base16lower "7b"
Just "123"
λ> encoder base10 <$> decoder base32lower "pm======"
Just "123"

Development

This project is part of ipfshs; unit tests are provided on the main page and bugs can be reported on its ticket tracker. Patches and pull requests can be submitted with git send-email. To build and test this project against all of ipfshs read this section on setting up an ipfshs development environment.

This project can also be built as a standalone library with cabal.

$ git clone https://git.sr.ht/~z0/basesystems
$ cd basesystems
$ cabal build

Licensing

The basesystems project and its modules are free software and licensed under the BSD 3-clause license. See LICENSE.txt.

Copyright © 2026 Zoey McBride | zoeymcbride@mailbox.org