Ошибка распаковки формата исправления OpenCDO8583.Net BCD
Я скачал код с code.google и получил последнюю версию v0.5.2
Я установил поле в формате bcd fix, это N-6 в формате bcd (bit._003_proc_code)
Например:
* Определение поля :
DefaultTemplate = новый шаблон {
{ Bit._002_PAN, FieldDescriptor.BcdVar(2, 19,Formatters.Ascii) },
{ Bit._003_PROC_CODE, FieldDescriptor.BcdFixed(3)},
{ Bit._004_TRAN_AMOUNT, FieldDescripted(6))..............}
использование:
Iso8583 msg =new Iso8584();
msg[3]="000000";
когда я распаковываю сообщение, я могу получить только "0000" из сообщения 3 .
это ошибка или ошибка в определении
1 ответ
Я бы подождал, чтобы услышать от Джона Оксли, чтобы увидеть, если это просто ошибка кодирования. Теперь, когда я сказал это, я думаю, что это ошибка.
У меня были проблемы с определением BcdFixed, и в итоге я создал новый форматер BCD фиксированной длины, чтобы обойти эту проблему.
Вот что я сделал:
Я создал класс с именем FixedLengthBcdFormatter, который является разновидностью класса FixedLengthFormatter.
/// /// Исправлено средство форматирования поля /// открытый класс FixedLengthBcdFormatter: ILengthFormatter {private readonly int _packedLength; private readonly 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
}
Изменен класс FieldDescription / объявление BcdFixed
/// /// Bcd исправлен. /// /// /// Длина. /// /// /// public static IFieldDescriptor BcdFixed(int unpackedLength) { return Create(новый FixedLengthBcdFormatter(unpackedLength), FieldValidators.N, Formatters.Bcd, null); }
Затем измените объявление форматера, указав в качестве параметра распакованную длину.
Bit._003_PROC_CODE, FieldDescriptor.BcdFixed (6)},
Опять же, все это, возможно, было ненужным, потому что я ничего не знал о существующем коде, но он работает для меня.
Надеюсь, это поможет.