@Override public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try { int len = prefixer.decodeLength(b, offset); if (len == -1) { // The prefixer doesn't know how long the field is, so use // maxLength instead len = getLength(b, offset); } int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + lenLen, len); c.setValue(unpacked); return lenLen + interpreter.getPackedLength(len); } catch (Exception e) { throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }
@Override public byte[] pack(ISOComponent c) throws ISOException { try { String data = (String) c.getValue(); // System.out.println(data); String paddedData = padder.pad(data, getLength()); byte[] rawData = new byte [prefixer.getPackedLength() + interpreter.getPackedLength(paddedData.getBytes().length)]; prefixer.encodeLength(paddedData.getBytes().length, rawData); interpreter.interpret(paddedData, rawData, prefixer.getPackedLength()); return rawData; } catch (Exception e) { e.printStackTrace(); throw new ISOException(makeExceptionMessage(c, "packing"), e); } }