package org.jpos.iso;

/**
 * ISOFieldPackager ASCII variable len CHAR 
 * suitable for EuroPay subfield 48<br>
 * <pre>
 * Format LLTT....
 * Where LL is the 2 digit field length
 *       TT is the 2 digit field number (Tag)
 *       is the field content   
 * </pre>
 *
 * @author apr@cs.com.uy
 * @version $Id$
 * @see ISOComponent
 */
public class IFEP_LLCHAR extends ISOFieldPackager {
    /**
     * @param len - field len
     * @param description symbolic descrption
     */
    public IFEP_LLCHAR (int len, String description) {
        super(len, description);
    }
    /**
     * @param c - a component
     * @return packed component
     * @exception ISOException
     */
    public byte[] pack (ISOComponent c) throws ISOException {
        int len;
        String s = (String) c.getValue();
    
        if ((len=s.length()) > getLength() || len>99)   // paranoia settings
            throw new ISOException (
                "invalid len "+len +" packing LLEPCHAR field "+(Integer) c.getKey()
            );

        return (
	    ISOUtil.zeropad(Integer.toString(len), 2) 
	   +ISOUtil.zeropad(((Integer) c.getKey()).toString(), 2) 
	   +s
	).getBytes();
    }

    /**
     * @param c - the Component to unpack
     * @param b - binary image
     * @param offset - starting offset within the binary image
     * @return consumed bytes
     * @exception ISOException
     */
    public int unpack (ISOComponent c, byte[] b, int offset)
        throws ISOException
    {
        int len = Integer.parseInt(new String(b, offset, 2));
	if (!(c instanceof ISOField))
	    throw new ISOException 
		(c.getClass().getName() + " is not an ISOField");

	((ISOField)c).setFieldNumber (
	    Integer.parseInt(new String(b, offset+2, 2))
	);
        c.setValue (new String (b, offset+4, len-2));
        return len + 2;
    }
    public int getMaxPackedLength() {
        return getLength() + 2;
    }
}

@@ -16,16 +16,46 @@
 s.iso;%0A%0A
+/*%0A * vim:set ts=8 sw=4:%0A */%0A%0A
 /**%0A * I
@@ -310,21 +310,63 @@
 hor 
-apr@cs.com.uy
+%3Ca href=%22mailto:eoin.flood@orbiscom.com%22%3EEoin Flood%3C/a%3E
 %0A * 
@@ -928,17 +928,17 @@
 %7C%7C len%3E9
-9
+7
 )   // p
@@ -1053,16 +1053,19 @@
  field %22
+%0A%09%09
 +(Intege
@@ -1152,16 +1152,18 @@
 ring(len
++2
 ), 2) %0A%09

The length of the field should be <= 97 to allow for the 2 digit field ID The field length indicator should include the 2 digit field id (Eoin Flood <eoin.flood@orbiscom.com>)