Copyright | (c) Ilya Portnov 2014 |
---|---|
License | BSD3-style (see LICENSE) |
Maintainer | portnov84@rambler.ru |
Stability | unstable |
Portability | not tested |
Safe Haskell | None |
Language | Haskell98 |
This module contains QuasiQuoter for declarative description of ISO 8583-based message formats.
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)
Supported field types
data FieldValue Source
Supported field values
Field format description
string2data :: String -> Q [Dec] Source
Generate only data type definition
Main function here.