#!/usr/bin/env elixir # Simple test to debug IFB_LLNUM field 2 parsing issue # Add the lib path Code.prepend_path("lib") # Import required modules alias DaProductApp.MercuryISO8583.Packagers.FieldPackagers.IFB_LLNUM # Test data from user: "3747404231320090008000" should be "374740423132009" (15 digits) # The user said consumed_bytes: 12, so let's simulate the raw data # Let's assume the raw data has a length prefix of 15 (0x15) followed by BCD data # For 15 digits, we need 8 bytes of BCD data (15 digits = 8 bytes since 2 digits per byte) # Create test data: length prefix 0x15 + 8 bytes of BCD data for "374740423132009" length_prefix = <<0x15>> # 21 decimal, but should be 15 # BCD encoding of "374740423132009" (15 digits) # 37 47 40 42 31 32 00 90 00 80 00 -> but we need to pack into 8 bytes # Actually, let's calculate properly: # "374740423132009" -> 15 digits # BCD packed: 8 bytes (since 15 digits needs 8 bytes: 7*2 + 1 = 15) bcd_data = <<0x37, 0x47, 0x40, 0x42, 0x31, 0x32, 0x00, 0x90>> # This represents "374740423132009" test_data = length_prefix <> bcd_data IO.puts("Test data: #{inspect(test_data)}") IO.puts("Test data hex: #{Base.encode16(test_data)}") # Test unpacking case IFB_LLNUM.unpack(%{}, test_data, 0, 2) do {:ok, {result, new_offset}} -> IO.puts("Success! Result: #{inspect(result)}") IO.puts("New offset: #{new_offset}") IO.puts("Parsed value: #{result.value}") {:error, reason} -> IO.puts("Error: #{reason}") end # Test with user's exact case: "3747404231320090008000" should be truncated to "374740423132009" # This is 22 digits, BCD encoded as 11 bytes length_prefix5 = <<0x22>> # 22 decimal bcd_data5 = <<0x37, 0x47, 0x40, 0x42, 0x31, 0x32, 0x00, 0x90, 0x00, 0x08, 0x00>> # 11 bytes test_data5 = length_prefix5 <> bcd_data5 IO.puts("Test data 5 (user's case): #{Base.encode16(test_data5)}") case IFB_LLNUM.unpack(%{}, test_data5, 0, 2) do {:ok, {result, _new_offset}} -> IO.puts("Success! Result: #{inspect(result)}") IO.puts("Parsed value: #{result.value}") IO.puts("Length of parsed value: #{String.length(result.value)}") IO.puts("Should be truncated from 22 to 15 digits") {:error, reason} -> IO.puts("Error: #{reason}") end