001/*
002 * jPOS Project [http://jpos.org]
003 * Copyright (C) 2000-2026 jPOS Software SRL
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jpos.iso;
020
021/**
022 * Implementations convert Strings into byte arrays and vice versa.
023 * 
024 * @author joconnor
025 * @version $Revision$ $Date$
026 */
027public interface Interpreter
028{
029    /**
030     * Converts the string data into a different interpretation. Standard
031     * interpretations are ASCII, EBCDIC, BCD and LITERAL.
032     * @param data the string data to interpret
033     * @param b    the target byte array
034     * @param offset the offset in {@code b} to start writing at
035     * @throws ISOException on error
036     */
037    void interpret(String data, byte[] b, int offset) throws ISOException;
038
039    /**
040         * Converts the byte array into a String. This reverses the interpret
041         * method.
042         * 
043         * @param rawData
044         *            The interpreted data.
045         * @param offset
046         *            The index in rawData to start interpreting at.
047         * @param length
048         *            The number of data units to interpret.
049     * @return The uninterpreted data.
050     * @throws ISOException on error
051     */
052    String uninterpret(byte[] rawData, int offset, int length) throws ISOException;
053
054    /**
055         * Returns the number of bytes required to interpret a String of length
056         * nDataUnits.
057         */
058    /**
059     * Returns the number of bytes needed to store {@code nDataUnits} data units in this interpretation.
060     * @param nDataUnits the number of logical data units
061     * @return the packed byte length
062     */
063    int getPackedLength(int nDataUnits);
064}