Skip to content

Latest commit

 

History

History
109 lines (80 loc) · 4.59 KB

README.md

File metadata and controls

109 lines (80 loc) · 4.59 KB

Module iso-8583-packer

The module is a library for creation, packing and unpacking ISO 8583 messages, and also for messages in non-standard formats.

Usage

The module is the source of the iso-8583-packer-1.0.51 library.

The library can be loaded from the Maven Central Repository.

Example of Maven configuration in a pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    ... some mandatory tags omitted

    <dependencies>
        <dependency>
            <groupId>com.credibledoc</groupId>
            <artifactId>iso-8583-packer</artifactId>
            <version>1.0.51</version>
        </dependency>
    </dependencies>

</project>

Examples

Fixed - length value without a tag

The code below will create a new instance of the FieldBuilder with a single field. The field will contain 2 bytes data in BCD format.

            FieldBuilder.builder(MsgFieldType.VAL)
                .defineLen(2)
                .defineBodyPacker(BcdBodyPacker.leftPadding0());

The field can be filled with data by ValueHolder, for example:

            String value = "123";
            ValueHolder valueHolder =
                ValueHolder.newInstance(fieldBuilder.getCurrentField())
                .setValue(value);

The filled object can be packed into bytes

            byte[] valueBytes = valueHolder.pack();
            String bytesHex = HexService.bytesToHex(valueBytes);
            assertEquals("0123", bytesHex);

The defined MsgField can be used for unpacking from bytes to an object

            String packedHex = "0456";
            byte[] packedBytes = HexService.hex2byte(packedHex);
            
            MsgValue msgValue =
                ValueHolder.newInstance(fieldBuilder.getCurrentField())
                .unpack(packedBytes);
            String unpackedValue = (String) msgValue.getBodyValue();
    
            String expectedValue = "456";
            assertEquals(expectedValue, unpackedValue);

You can find the complete example here: BcdBodyPackerTest

More complex message definition with inner subfields is described in the complex-example.md document.

Field types

Every field contains a header (optional) and a body (mandatory), for example 02 01 03, where

  • 02 is header TAG
  • 01 is header LEN
  • 03 is body VAL

The FieldBuilder is able to create different field types, with and without headers, see the field-types.md document.

TAG types and packers

The following page tag-packer.md describes some formats and types of TAG packers.

LEN types and packers

The following length-packer.md page describes different LEN subfield types and implementations of the LengthPacker interface.

VAL types and packers

The following page body-packer.md contains description of different formats of body values.

Masker

In a production environment it is necessary to mask private sensitive data before print it to a log file. The following page masker.md describes how to mask the data.

Bitmap

The ISO 8583 standard uses Bitmaps for defining of field numbers placed on a message.

The following bitmap-packer.md page describes how to define and use bitmaps.

Repeated fields

In some cases is required to repeat some values in messages, for example to send multiple products purchased by a customer.

The following example repeated-tag-val.md explains how to pack and unpack multiple recurrent fields.