machines-binary-0.5.0.0: Binary utilities for the machines library
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Binary.Machine

Contents

Synopsis

Get

processGetL :: Get a -> Plan (Stack ByteString) (Either DecodingError (ByteOffset, a)) () Source #

Same as stackGet with additional information about the number of bytes consumed by the Get

stackGet :: Get a -> Plan (Stack ByteString) (Either DecodingError a) () Source #

Construct a Plan that run a Get until it fails or it return a parsed result. This plan automatically manages the pushback of unused input.

You can use this function to construct a machine and run a Get on the provided input. With stack you can convert the created machine to a normal machine

-- construct the machine
myMachine :: Machine (Stack ByteString) (Either DecodingError Word8)
myMachine = construct $ stackGet getWord8

-- run the machine
run $ stack (source ["abc", "d", "efgh"]) myMachine

You can combine machines created in this way with the facilities provided by the machines package.

--run m2 after m1
myMachine = m1 <> m2
  where
    m1 = construct $ stackGet (getByteString 5)
    m2 = construct $ stackGet (getByteString 1)

run $ stack (source ["abc", "d", "efgh"]) myMachine
> [Right "abcde",Right "f"]

streamGet :: Get a -> Process ByteString (Either DecodingError a) Source #

Run a Get multiple times and stream its results

run $ source ["abc", "d", "efgh"] ~> streamGet (getByteString 2)
> [Right "ab",Right "cd",Right "ef",Right "gh"]

streamGetL :: Get a -> Process ByteString (Either DecodingError (ByteOffset, a)) Source #

Same as streamGet with additional information about the number of bytes consumed by the Get

Put

Types

data DecodingError Source #

A Get decoding error.

Constructors

DecodingError 

Fields