001    /**
002     *
003     * Copyright 2004 Protique Ltd
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     * http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     *
017     **/
018    
019    
020    package org.activemq.io.impl;
021    import java.io.DataOutput;
022    import java.io.IOException;
023    
024    import org.activemq.message.Packet;
025    
026    /**
027     * Allows instances implementing Packet to written to a DataOutput
028     */
029    
030    public interface PacketWriter {
031    
032        /**
033         * Return the type of Packet
034         *
035         * @return integer representation of the type of Packet
036         */
037    
038        public int getPacketType();
039    
040        /**
041         * @param packet
042         * @return true if this PacketWriter can write this type of Packet
043         */
044        public boolean canWrite(Packet packet);
045    
046        /**
047         * Write a Packet instance to data output stream
048         *
049         * @param packet  the instance to be seralized
050         * @param dataOut the output stream
051         * @throws IOException thrown if an error occurs
052         */
053    
054        public void writePacket(Packet packet, DataOutput dataOut) throws IOException;
055    
056        /**
057         * Serializes a Packet int a byte array
058         *
059         * @param packet
060         * @return the byte[]
061         * @throws IOException
062         */
063    
064        public byte[] writePacketToByteArray(Packet packet) throws IOException;
065        
066        /**
067         * Set the wire format version
068         * @param version
069         */
070        public void setWireFormatVersion(int version);
071        
072        /**
073         * @return the wire format version
074         */
075        public int getWireFormatVersion();
076        
077    
078    }