iso8583-bitmaps-0.1.1.0: Parse and merge ISO 8583-style bitmaps

Copyright(c) Ilya Portnov 2014
LicenseBSD3-style (see LICENSE)
Maintainerportnov84@rambler.ru
Stabilityunstable
Portabilitynot tested
Safe HaskellSafe
LanguageHaskell98

Data.Binary.ISO8583

Contents

Description

This module contains Get and Put method implementations for ISO 8583 style bitmaps, and also utility methods for getting/putting fields in formats commonly used in ISO 8583 specification.

Synopsis

Usage

Typical usage is:

data Message = Message {pan :: B.ByteString, stan :: Integer}
deriving (Eq, Show)
data FieldValue = String B.ByteString | Int Integer
deriving (Eq, Show)
getField :: Int -> Maybe (Get FieldValue)
getField 2 = Just $ String `fmap` embeddedLen 2
getField 11 = Just $ Int `fmap` asciiNumberF 11 6
getField _ = Nothing
getMessage :: Get Message
getMessage = do
  m <- getBitmap getField
  let Just (String pan) = M.lookup 2 m
  let Just (Int stan) = M.lookup 11 m
  return $ Message pan stan
putMessage :: Message -> Put
putMessage (Message pan stan) = do
  putBitmap [(2, putEmbeddedLen 2 pan),
             (11, putAsciiNumber 6 stan)] 

getBitmapFieldNumbers :: Get [Int] Source #

Parse bitmap. Return numbers of fields present. NB: only two bitmaps are supported as for now (Primary and Secondary bitmaps in ISO 8583 notation).

getBitmap Source #

Arguments

:: (Int -> Maybe (Get f))

Parser for n'th field, or Nothing if field is not supported

-> Get (Map Int f) 

Parse ISO 8583-style bitmap. Fails if unsupported field is present in message.

mergeFieldNumbers :: [Int] -> ByteString Source #

Merge numbers of fields present into ISO bitmap.

putBitmap Source #

Arguments

:: [(Int, Put)]

(Field number, field putter)

-> Put 

Put ISO 8583-style bitmap.

putBitmap' Source #

Arguments

:: [(Int, Maybe Put)]

(Field number, field putter or Nothing if field is not present)

-> Put 

Put ISO 8583-style bitmap.

embeddedLen Source #

Arguments

:: Int

Field number (to be used in error message)

-> Int

Number of bytes used for length (2 for LLVAR, 3 for LLLVAR and so on)

-> Get ByteString 

Parse string with embedded length (LLVAR/LLLVAR in ISO 8583 notation)

asciiNumber Source #

Arguments

:: Int

Number length

-> Get Int 

Parse number of given length in ASCII notation

asciiNumberF Source #

Arguments

:: Int

Field number, to be used in error message

-> Int

Number length

-> Get Integer 

Parse number of given length in ASCII notation; Report bitmap field number in case of error.

putAsciiNumber Source #

Arguments

:: Int

Number length

-> Integer

Number

-> Put 

Put number of given length in ASCII notation

putEmbeddedLen Source #

Arguments

:: Int

Number of bytes used for length (2 for LLVAR, 3 for LLLVAR and so on)

-> ByteString

String to put

-> Put 

Put string with embedded length (LLVAR/LLLVAR in ISO 8583 notation)

putByteStringPad Source #

Arguments

:: Int

Field length

-> ByteString

String to put

-> Put 

Put space-padded string of given length

putLazyByteStringPad Source #

Arguments

:: Int64

Field length

-> ByteString

String to put

-> Put 

Put space-padded string of given length