/*
 * TypeBinaryWriter.java
 * 
 * (C) 28.02.2005 Markus Schaber, Logi-Track ag, CH 8001 Zuerich
 * 
 * $Id: $
 */
package org.postgresql.types;

import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;

public interface TypeBinaryWriter extends TypeDriver {

    /**
     * Return the length of an encoded object in bytes.
     * 
     * This method can calculate the length on actual data. You can call it with
     * any object the driver accepts via set* methods.
     * 
     * @return the lenght in bytes, -1 for unknown.
     * @throws SQLException if the driver does not know to handle the object or
     *             something else goes wrong.
     */
    int objectBytesLength(Object data) throws SQLException;

    /** Render the object into the SQL binary representation */
    void renderObject(Object data, byte[] target, int startindex);

    /**
     * Render the object into the SQL binary representation
     */
    void renderObject(Object data, OutputStream outstream) throws SQLException, IOException;
}
