From bec6340fe5c0ec9555af0bc9bb403f54a4cda9b7 Mon Sep 17 00:00:00 2001 From: Enrique Zamudio Date: Tue, 26 Nov 2013 18:49:21 -0600 Subject: [PATCH] fix length calculation --- .../java/com/solab/iso8583/codecs/CompositeField.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/solab/iso8583/codecs/CompositeField.java b/src/main/java/com/solab/iso8583/codecs/CompositeField.java index e381cc9..51e9049 100644 --- a/src/main/java/com/solab/iso8583/codecs/CompositeField.java +++ b/src/main/java/com/solab/iso8583/codecs/CompositeField.java @@ -72,7 +72,13 @@ public class CompositeField implements CustomBinaryField { for (FieldParseInfo fpi : parsers) { IsoValue v = fpi.parseBinary(0, buf, pos, null); if (v != null) { - pos += v.getLength(); + if (v.getType() == IsoType.NUMERIC || v.getType() == IsoType.DATE10 + || v.getType() == IsoType.DATE4 || v.getType() == IsoType.DATE_EXP + || v.getType() == IsoType.AMOUNT || v.getType() == IsoType.TIME) { + pos += (v.getLength() / 2) + (v.getLength() % 2); + } else { + pos += v.getLength(); + } if (v.getType() == IsoType.LLVAR || v.getType() == IsoType.LLBIN) { pos++; } else if (v.getType() == IsoType.LLLVAR || v.getType() == IsoType.LLLBIN) { @@ -102,7 +108,7 @@ public class CompositeField implements CustomBinaryField { for (FieldParseInfo fpi : parsers) { IsoValue v = fpi.parse(0, buf, pos, null); if (v != null) { - pos += v.getLength(); + pos += v.toString().getBytes(fpi.getCharacterEncoding()).length; if (v.getType() == IsoType.LLVAR || v.getType() == IsoType.LLBIN) { pos+=2; } else if (v.getType() == IsoType.LLLVAR || v.getType() == IsoType.LLLBIN) {