ISO8583 Field lengths with unicode characters

Viewed 466

Iso8583 messages can contain variable length fields, such as field 44/an ..25/Additional response data. Currently we are calculating these fields based on the character length, however we have added support for right-double-quote () and right-single-quote () which require UTF-8. These characters get encoded as three bytes, which means that the byte length and character/string length are no longer equal, and this breaks some of our processes.

My question is - does the Iso8583 standard require that the field length is bytes or characters?

Wikipedia is inconsistent and most other sources I've found aren't really explicit.

1 Answers

if you want to have Unicode characters in an special field, the ISO8583 standard does not limit you for this.

you can develop a new field parser which gets byte stream/array and converts it to string and then sets that string to field data, in C# convertion to string is enough(because .net engine uses Unicode as it's primary encoding to store strings)

Here is an example which uses OpenIso8583Net library:

using System.Text;

namespace OpenIso8583Net.Formatter
{
    /// <summary>
    ///   UTF8 Field Formatter
    /// </summary>
    public class UTF8Formatter : IFormatter
    {
        #region IFormatter Members

        /// <summary>
        ///   Format the string and return as an encoded byte array
        /// </summary>
        /// <param name = "value">value to format</param>
        /// <returns>Encoded byte array</returns>
        public byte[] GetBytes(string value)
        {
            return Encoding.UTF8.GetBytes(value);
        }

        /// <summary>
        ///   Format the string and return as an encoded byte array
        /// </summary>
        /// <param name = "value">value to format</param>
        /// <param name="length"> </param>
        /// <returns>Encoded byte array</returns>
        public byte[] Pack(string value, int length)
        {
            return Encoding.UTF8.GetBytes(value.PadLeft(length, '0'));
        }

        /// <summary>
        ///   Length for UTF8 is not Implemented Completely!
        ///   Format the string and return as an encoded byte array 
        /// </summary>
        /// <param name = "value">value to format</param>
        /// <param name="length"> </param>
        /// <returns>Encoded byte array</returns>
        public byte[] GetBytes(string value, int length)
        {
            return Encoding.UTF8.GetBytes(value);
        }

        /// <summary>
        ///   Takes the byte array and converts it to a string for use
        /// </summary>
        /// <param name = "data">Data to convert</param>
        /// <returns>Converted data</returns>
        public string GetString(byte[] data)
        {
            return Encoding.UTF8.GetString(data);
        }

        /// <summary>
        ///   Gets the packed length of the data given the unpacked length
        /// </summary>
        /// <param name = "unpackedLength">Unpacked length</param>
        /// <returns>Packed length of the data</returns>
        public int GetPackedLength(int unpackedLength)
        {
            return unpackedLength;
        }

        #endregion
    }
}
Related