0

我从code.google下载了代码并得到了最新版本v0.5.2
我设置了一个bcd fix格式的字段,即bcd格式的N-6(bit._003_proc_code)
例如:
*字段定义:<br/> DefaultTemplate =新模板 { { Bit._002_PAN, FieldDescriptor.BcdVar(2, 19,Formatters.Ascii) }, { Bit._003_PROC_CODE, FieldDescriptor.BcdFixed(3)}, { Bit._004_TRAN_AMOUNT, FieldDescriptor.BcdFixed(6) }, . ...... }

用法:

Iso8583 msg =new Iso8584();
msg[3]="000000";

当我解包消息时,我只能从消息 3 中得到“0000”。
这是定义中的错误还是错误

4

1 回答 1

0

我会等着听 John Oxley 的消息,看看这是否只是一个编码错误。既然我这么说,我认为这是一个错误。

我遇到了 BcdFixed 定义的问题,最终创建了一个新的 Fixed Length BCD 格式化程序来解决这个问题。

这是我所做的:

  1. 我创建了一个名为 FixedLengthBcdFormatter 的类,它是 FixedLengthFormatter 类的变体。

    /// /// 固定字段格式化程序 /// public class FixedLengthBcdFormatter : ILengthFormatter { private readonly int _packedLength; 私有只读 int _unPackedLength;

    ///<summary>
    ///  Fixed length field formatter
    ///</summary>
    ///<param name = "unPackedLength">The unpacked length of the field.</param>
    public FixedLengthBcdFormatter(int unPackedLength)
    {
        _unPackedLength = unPackedLength;
        double len = _unPackedLength;
       _packedLength =  (int)Math.Ceiling(len / 2);
    }
    
    #region ILengthFormatter Members
    
    /// <summary>
    ///   Get the length of the packed length indicator.  For fixed length fields this is 0
    /// </summary>
    public int LengthOfLengthIndicator
    {
        get { return 0; }
    }
    
    /// <summary>
    ///   The maximum length of the field displayed as a string for descriptors
    /// </summary>
    public string MaxLength
    {
        get { return _unPackedLength.ToString(); }
    }
    
    /// <summary>
    ///   Descriptor for the length formatter used in ToString methods
    /// </summary>
    public string Description
    {
        get { return "FixedBcd"; }
    }
    
    /// <summary>
    ///   Get the length of the field
    /// </summary>
    /// <param name = "msg">Byte array of message data</param>
    /// <param name = "offset">offset to start parsing</param>
    /// <returns>The length of the field</returns>
    public int GetLengthOfField(byte[] msg, int offset)
    {
        return _unPackedLength;
    }
    
    /// <summary>
    ///   Pack the length header into the message
    /// </summary>
    /// <param name = "msg">Byte array of the message</param>
    /// <param name = "length">The length to pack into the message</param>
    /// <param name = "offset">Offset to start the packing</param>
    /// <returns>offset for the start of the field</returns>
    public int Pack(byte[] msg, int length, int offset)
    {
        return offset;
    }
    
    /// <summary>
    ///   Check the length of the field is valid
    /// </summary>
    /// <param name = "packedLength">the packed length of the field</param>
    /// <returns>true if valid, false otherwise</returns>
    public bool IsValidLength(int packedLength)
    {
        return packedLength == _packedLength;
    }
    
    #endregion
    

    }

  2. 修改了 FieldDescription 类/BcdFixed 声明

    /// /// bcd 已修复。/// /// /// 长度。/// /// /// public static IFieldDescriptor BcdFixed(int unpackedLength) { return Create(new FixedLengthBcdFormatter(unpackedLength), FieldValidators.N, Formatters.Bcd, null); }

  3. 然后更改您的格式化程序声明以提供解包长度作为参数。

    Bit._003_PROC_CODE, FieldDescriptor.BcdFixed(6)},

同样,所有这些可能都是不必要的,因为我对现有代码一无所知,但它对我有用。

我希望这有帮助。

于 2012-05-16T04:53:52.867 回答