Source code: RecordFormat.java

index |  50 lines | javadoc ]

package nl.west.aaa;

import java.io.*;

/**
 * Classes implementing this interface can
 * code Messages to send to a sream and
 * read Messages from a stream.
 */
public interface RecordFormat
{

    /**
     * Encode a given message.
     */
    public byte[] encodeMessage(Message msg);

    /**
     * Read a Message from a stream.
     * The stream should not be closed
     * and no more data than neccesary should be read.
     * <br>
     * If the stream does not contain this
     * record format null should be returned (no exceptions thrown)
     * and the stream should be reset to where it was
     * before the call, useing mark() and reset(). The
     * stream passed as an argument supports mark() and
     * reset().
     * <br>
     * Any recordformat should ensure that a "sid" (session id)
     * attribute is present in the message. This attribute is used
     * for matching replies with requests.
     */
    public Message decodeMessage(InputStream in,Identifier from)
        throws IOException;
    
    /**
     * Read a Message from a byte array.
     * The data should contain one complete message.
     * <br>
     * If the data is not a message of this record format,
     * null should be returned (no exceptions thrown).
     * <br>
     * Any recordformat should ensure that a "sid" (session id)
     * attribute is present in the message. This attribute is used
     * for matching replies with requests.
     */
    public Message decodeMessage(byte[] data,Identifier from);
  
}


Arthur <arthur@ch.twi.tudelft.nl> http://ch.twi.tudelft.nl/~arthur/
2002-05-27