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

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

Data.Binary.ISO8583.TH

Contents

Description

This module contains QuasiQuoter for declarative description of ISO 8583-based message formats.

Synopsis

Usage

Typical usage is:

[binary|
  Message
  2 pan embedded 2
  4 amount int 12
  11 stan int 6
  43 termAddress TermAddress 222
|]
data TermAddress = TermAddress ...
instance Binary TermAddress where ...

Quasi-quote format is:

  • First line - name of data type to generate
  • Each of other lines describes one field, in following format: {Field number} {Field name} {data type} {type parameter}

Internally supported data types are:

  • int - integer field. Parameter defines size of field.
  • str - fixed-length string field. Parameter defines size of field.
  • embedded - embedded-length string field. Parameter defines number of bytes used to store field length (2 for LLVAR, 3 for LLLVAR and so on).

Any other data type, instance of Binary class, may be used as well.

Quasi-quoter generates data type definition, and also following functions:

  • get[Message] :: Int -> Maybe (Get FieldValue)
  • put[Message] :: Message -> [(Int, Maybe Put)]
  • construct[Message] :: M.Map Int FieldValue -> Message

Concrete ISO 8583-based formats usually use some kind of message header, or use bitmap only as small part of overall format. So, it's usually no point of generating instance Binary Message - it's better to write instance for your format by using functions mentioned above.

instance Binary Message where
  get = do
    -- parse some kind of header here, then:
    m <- getBitmap getMessage
    return $ constructMessage m
  
  put msg = do
    -- write some kind of header here, then:
    putBitmap' (putMessage msg)

data FieldType Source

Supported field types

Constructors

TInt Int

Integer field of given size

TString Int

Fixed-length string field

TEmbeddedLen Int

Variable-length string field with embedded length (LLVAR and so on)

TOther String Int

User-defined field - any data type with instance Binary. NB: second parameter is not used currently.

data FieldValue Source

Supported field values

Constructors

FInt Integer

Integer field

FString ByteString

String fields

forall t . (Binary t, Show t, Typeable t) => FOther t

User-defined field

data Field Source

Field format description

Constructors

Field 

Fields

fNumber :: Int

Field number

fName :: String

Field name

fType :: FieldType

Field type description

Instances

pData :: Parser (String, [Field]) Source

Parse data format definition

string2data :: String -> Q [Dec] Source

Generate only data type definition

binary :: QuasiQuoter Source

Main function here.