Closed ddvk closed 1 year ago
Hey! Thanks for reporting the issue! I’ll take a look.
@ddvk Sorry for such a long delay with the issue review. I see one problem with the example you provided. For field 2
length is Length: 2,
but you set value of the length 4
(1234
). If you set Length: 4
it will work as expected.
Length - is not about the final encoded length. As it says here https://github.com/moov-io/iso8583/blob/master/field/spec.go#L43:
// Length defines the maximum length of field (bytes, characters or
// digits), for both fixed and variable lengths.
Using 34
as field value works for me when length is 2
. 1234
works for me when length is 4
.
@ddvk while Length
in the documentation says that it's about field length, in the prefixer code I see we are using the length of the encoded data. I need to review it one more time.
I had 2 issues. in the example, I would expect the field length to apply to the field data. In variable length encoding, it get's truncated. updated the code the example code
When using BCD.Fixed, my expectation was that the length is in Nibbles i.e. number of digits.
However, encoding checks and uses the length in bytes, but the Decoding uses the length in digits.
There is no error during packing, and the other side cannot correctly decode the message as the field is larger than the spec and further fields are clobbered.
Example