Selama ini gw selalu pake jpos, dan jpos itu dokumentasinya berbayar (kalo ga salah 50 USD harganya). Ga pernah kepikiran bikin parser sendiri.

Sampai akhirnya ada yg request buat parser dalam bahasa pascal. Gw sempetin diantara sela-sela kerjaan.. akhirnya jadi pula.

Berikut ini saya share source code untuk parsing iso8583 dalam bahasa pascal. Akan tetapi, source code berikut ini hanyalah basic algorithm, dan hanya untuk message iso 8583 64 bit. Untuk yg 128 / 192 bit harus diubah lagi packagernya. (males gw ngubahnya, abis kepanjangan wkwkwk).

Oiya, program ini membaca iso string yg disimpan dalam file test.txt. Jadi buat dulu file bernama test.txt yang berisi iso 8583 string yang akan diparsing. Ini contoh iso 8583 yg akan diparsing:

01002220050028C010041100000619163620193776021046316278790012300001=15031011000000000000000003ABCD0123TESTINGABCD0123F713B5B0ED3D0A61006000003

Untuk source code parsernya, silakan dilihat-lihat:

uses crt;

type bit=record
  id:byte;
  name:string[50];
  length:word;
  toggle:boolean;
  end;

  (* dalam contoh ini gw bikin packager utk iso 8583 64bit *)
  (* silakan expand sendiri utk yg 128/192 bit *)
type packager_iso8583_64bit = array [0..63] of bit;

  (* utk private bit, semua gw kasih tipe LLLVAR..999  *)
const array_of_length:array[0..63] of word =
      (
        4, 16, 19, 6, 12, 12, 12, 10, 8, 8, 8,
        6, 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3,
        3, 2, 2, 1, 9, 9, 9, 9, 11, 11, 28, 37,
        104, 12, 6, 2, 3, 8, 15, 40, 25, 76, 999,
        999, 999, 3, 3, 3, 16, 16, 120, 999, 999,
        999, 999, 999, 999, 999, 999, 999
      );

(* array of name field nya bikin sendiri aja ya,
   soalnya panjang banget dan banyak banget :P *)
function hexToDec(arg0:string):integer;
var
  temp_a,temp_b:word;
begin
  if (arg0[1] in ['A','B','C','D','E','F']) then
    temp_a:=(ord(arg0[1])-55)*16
  else
    temp_a:=(ord(arg0[1])-48)*16;
  if (arg0[2] in ['A','B','C','D','E','F']) then
    temp_b:=(ord(arg0[2])-55)
  else
    temp_b:=(ord(arg0[2])-48);
  hexToDec:=temp_a+temp_b;
end;

function decToBin(arg0:integer):string;
var
  temp:integer;
  bin:string;
begin
  bin:='';
  while(arg0 > 0) do
    begin
      temp:=(arg0 mod 2);
      bin:=chr(temp+48)+bin;
      arg0:=arg0 div 2;
    end;
  while(length(bin)<8)do
    bin:='0'+bin;
  decToBin:=bin;
end;

var
  packager:packager_iso8583_64bit;
  i:byte;
  dec,j,pos,tempLen:integer;
  fText: text;
  temp,bin,isoString,toggleBit:string;
  tempHex:string[2];
  bitmap:string;

begin
  clrscr;
  (* create packager *)
  for i:=0 to 63 do
    begin
      packager[i].id := i;
      packager[i].length := array_of_length[i];
      packager[i].toggle := false;
    end;

  assign(fText,'test.txt');
  reset(fText);
  read(fText,isoString);
  writeln('iso String= ',isoString);
  close(fText);

  writeln;
  temp := copy(isoString,1,4);
  writeln(0,' = ''',temp,'''');
  bitmap:=copy(isoString,5,16);
  writeln(1,' = ''',bitmap,'''');

  i:=1;
  toggleBit := '';
  while i<length(bitmap) do
    begin

      tempHex:=copy(bitmap,i,2);
      dec:=hexToDec(tempHex);
      bin:=decToBin(dec);
      toggleBit := toggleBit + bin;
      i:=i+2;
    end;

  pos:=4+16;
  for i:=3 to length(toggleBit) do
    begin
      if(toggleBit[i]='1')then
        begin
          if i=35 then
           begin
             packager[i].toggle := true;
             Val(copy(isoString,pos+1,2),tempLen,dec);
             pos:= pos + 2;
             writeln(i,' = ''',copy(isoString,pos+1,tempLen),'''');
             pos:= pos + tempLen;
           end
          else if(packager[i].length<>999)then
            begin
              packager[i].toggle := true;
              writeln(i,' = ''',copy(isoString,pos+1,packager[i].length),'''');
              pos:= pos + packager[i].length;
            end
          else
            begin
              packager[i].toggle := true;
              Val(copy(isoString,pos+1,3),tempLen,dec);
              pos:= pos + 3;
              writeln(i,' = ''',copy(isoString,pos+1,tempLen),'''');
              pos:= pos + tempLen;
            end;
        end;
    end;

  readln;
end.

note: Gw pake Turbo Pascal 7.0 (MS-DOS, OS Windows 32 bit)

About these ads