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.Serial

This module contains two main classes, each providing methods to serialize and deserialize types. Serial is the primary class, to be used for the canonical way to serialize a specific type. SerialEndian is used to provide endian-specific methods for serializing a type.

  • 7 classes
  • 6 values
  • Packagebytes-0.17.4
  • Exports13
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceSerial.hs

Serialization

1 declaration
classclass Serial a where
#

Methods to serialize and deserialize type a to a binary representation

Instances provided here for fixed-with Integers and Words are big endian. Instances for strict and lazy bytestrings store also the length of bytestring big endian. Instances for Word and Int are host endian as they are machine-specific types.

Methods

Instances66Serial, …
  • Serial ByteStringDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial ByteStringDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial IntSetDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial IntegerDefined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    (runGetL deserialize $ runPutL $ serialize (1822304234^100::Integer))::Integer115368812579128172803867366576339947332796540054052185472042218522037227934707037623902492207671987696439966697503243972076991940820348847422930433939639982092916577692754723458548819441583937289395076910527534916776189405228720063994377687015476947534961767053653973945346259230972683338173842343243493433367681264359887291905132383269175086733345253389374961758293922003996035662362278340494093804835649459223465051596978792130073960666112508481814461273829244289795707398202762289955919352549768394583446336873179280924584333491364188425976869717125645749497258775598562132278030402205794994603544837805140410310712693778605743100915046769381631247123664460203591228745772887977959388457679427407639421147498028487544882346912935398848298806021505673449774474457435816552278997100556732447852816961683577731381792363312695347606768120122976105200574809419685234274705929886121600174028733812771637390342332436695318974693376
  • Serial NaturalDefined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    runGetL deserialize (runPutL (serialize (10^10::Natural))) :: Natural10000000000
  • Serial VoidDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial AllDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial AnyDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial VersionDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial Int16Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial Int32Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial Int64Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial Int8Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial Word16Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial Word32Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial Word64Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial Word8Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial BoolDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial CharDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial DoubleDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial FloatDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial IntDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial OrderingDefined in bytes-0.17.4 · Data.Bytes.Serial
    Example3 expressions
    runGetL deserialize $ runPutL $ serialize LT::OrderingLTrunGetL deserialize $ runPutL $ serialize EQ::OrderingEQrunGetL deserialize $ runPutL $ serialize GT::OrderingGT
  • Serial WordDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial ScientificDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial TextDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial TextDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial DayDefined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    (runGetL deserialize $ runPutL $ serialize (ModifiedJulianDay 1))::Day1858-11-18
  • Serial AbsoluteTimeDefined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    (runGetL deserialize $ runPutL $ serialize (addAbsoluteTime 18.2 taiEpoch))::AbsoluteTime1858-11-17 00:00:18.2 TAI
  • Serial DiffTimeDefined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    (runGetL deserialize $ runPutL $ serialize (1.82::DiffTime))::DiffTime1.82s
  • Serial NominalDiffTimeDefined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    (runGetL deserialize $ runPutL $ serialize (1.82::DiffTime))::DiffTime1.82s
  • Serial UTCTimeDefined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    (runGetL deserialize $ runPutL $ serialize (read "2014-01-01 10:54:42.478031 UTC"::UTCTime))::UTCTime2014-01-01 10:54:42.478031 UTC
  • Serial UniversalTimeDefined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    getModJulianDate $ (runGetL deserialize $ runPutL $ serialize (ModJulianDate $ 5 % 11)::UniversalTime)5 % 11
  • Serial LocalTimeDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial TimeOfDayDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial TimeZoneDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial ZonedTimeDefined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial ()Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (Seq a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (NonEmpty a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (Identity a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (First a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (Last a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (Down a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (Dual a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (Product a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (Sum a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (ZipList a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (Maybe a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial [a]Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial v => Serial (IntMap v)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (Serial a, Integral a) => Serial (Ratio a)Defined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    (runGetL deserialize $ runPutL $ serialize (5 % 11::Ratio Int))::Ratio Int5 % 11
  • (Serial a, Ord a) => Serial (Set a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (Serial v, Hashable v, Eq v) => Serial (HashSet v)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (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"
  • HasResolution a => Serial (Fixed a)Defined in bytes-0.17.4 · Data.Bytes.Serial
    Example1 expression
    (runGetL deserialize $ runPutL $ serialize (1.82::Fixed E2))::Fixed E21.82
  • (Serial a, Serial b) => Serial (Either a b)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (Serial a, Serial b) => Serial (a, b)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (Serial k, Serial v, Ord k) => Serial (Map k v)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (Serial k, Serial v, Hashable k, Eq k) => Serial (HashMap k v)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial (f a) => Serial (Reverse f a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • Serial a => Serial (Constant a b)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (Serial a, Serial b, Serial c) => Serial (a, b, c)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (Serial (f a), Serial (g a)) => Serial (Product f g a)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (Serial a, Serial b, Serial c, Serial d) => Serial (a, b, c, d)Defined in bytes-0.17.4 · Data.Bytes.Serial
  • (Serial a, Serial b, Serial c, Serial d, Serial e) => Serial (a, b, c, d, e)Defined in bytes-0.17.4 · Data.Bytes.Serial

Specifying endianness

1 declaration
classclass SerialEndian a where
#

Methods to serialize and deserialize type a to a big and little endian binary representations. Methods suffixed with "host" are automatically defined to use equal the methods corresponding to the current machine's native endianness, but they can be overridden.

Methods

Instances9SerialEndian, …

Higher-order

6 declarations

These classes provide us with the ability to serialize containers that need polymorphic recursion.

classclass Serial1 (f :: Type -> Type) where
#

Methods

Instances12Serial1, …
classclass Serial2 (f :: Type -> Type -> Type) where
#

Methods

Instances5Serial2

Storable

2 declarations

Generics

3 declarations

You probably will never need to care that these exist except they provide us with default definitions for Serial and SerialEndian

classclass GSerial (f :: Type -> Type) where
#

Used internally to provide generic serialization

Methods

Instances6GSerial
classclass GSerial1 (f :: Type -> Type) where
#

Used internally to provide generic serialization

Methods

Instances9GSerial1, …