HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulebytes-0.17.4Haskell2010

Data.Bytes.VarInt

This module provides a VarInt wrapper with a Serial instance that generates base-128 variable-width ints. Values are encoded 7 bits at a time, with the most significant being a continuation bit. Thus, the numbers from 0 to 127 require only a single byte to encode, those from 128 to 16383 require two bytes, etc.

This format is taken from Google's Protocol Buffers, which provides a bit more verbiage on the encoding: https://developers.google.com/protocol-buffers/docs/encoding#varints.

  • 1 type
  • Packagebytes-0.17.4
  • Exports1
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceVarInt.hs
newtypenewtype VarInt n
#

Constructors

Instances12Bounded, Enum, Eq, Integral, Num, Ord, …
  • Bounded n => Bounded (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • Enum n => Enum (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • Eq n => Eq (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • Integral n => Integral (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • Num n => Num (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • Ord n => Ord (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • Real n => Real (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • Show n => Show (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • Bits n => Bits (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • (Bits n, Integral n, Bits (Unsigned n), Integral (Unsigned n)) => Serial (VarInt n)Defined in bytes-0.17.4 · Data.Bytes.Serial

    Integer/Word types serialized to base-128 variable-width ints.

    Example4 expressions
    import Data.Monoid (mconcat)import qualified Data.ByteString.Lazy as BSLmconcat $ BSL.toChunks $ runPutL $ serialize (97 :: Word64)"\NUL\NUL\NUL\NUL\NUL\NUL\NULa"mconcat $ BSL.toChunks $ runPutL $ serialize (97 :: VarInt Word64)"a"
  • type Unsigned (VarInt n) = VarInt (Unsigned n)Defined in bytes-0.17.4 · Data.Bytes.VarInt
  • type Signed (VarInt n) = VarInt (Signed n)Defined in bytes-0.17.4 · Data.Bytes.VarInt