我从code.google下载了代码并获得了最新版本v0.5.2
我设置了一个bcd修复格式的字段,它是bcd格式的N-6(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,FieldDescriptor.BcdFixed(6)},
..............
}
用法:
Iso8583 msg =new Iso8584();
msg[3]="000000";
当我解压缩消息时,我只能从消息3中获得“0000” 这是定义中的错误或错误
答案 0 :(得分:0)
我等着听John Oakley看这是否只是编码错误。现在,我说,我认为这是一个错误。
我遇到了BcdFixed定义的问题,最终创建了一个新的固定长度BCD格式化程序来解决这个问题。
这是我做的:
我创建了一个名为FixedLengthBcdFormatter的类,它是FixedLengthFormatter类的变体。
/// ///固定字段格式化程序 /// public class 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(new FixedLengthBcdFormatter(unpackedLength),FieldValidators.N,Formatters.Bcd,null); }
然后更改格式化程序声明以提供解压缩的长度作为参数。
Bit._003_PROC_CODE,FieldDescriptor.BcdFixed(6)},
同样,所有这些可能都是不必要的,因为我对现有代码一无所知,但它对我有用。
我希望这会有所帮助。