1 18 package org.apache.activemq.kaha; 19 20 import java.io.DataInput ; 21 import java.io.DataOutput ; 22 import java.io.IOException ; 23 import org.apache.activemq.kaha.Marshaller; 24 import org.apache.activemq.util.ByteSequence; 25 import org.apache.activemq.wireformat.WireFormat; 26 27 31 public class CommandMarshaller implements Marshaller<Object > { 32 33 private WireFormat wireFormat; 34 public CommandMarshaller(WireFormat wireFormat){ 35 this.wireFormat = wireFormat; 36 37 } 38 39 public void writePayload(Object object,DataOutput dataOut) throws IOException { 40 ByteSequence packet = wireFormat.marshal(object); 41 dataOut.writeInt(packet.length); 42 dataOut.write(packet.data, packet.offset, packet.length); 43 } 44 45 46 public Object readPayload(DataInput dataIn) throws IOException { 47 int size=dataIn.readInt(); 48 byte[] data=new byte[size]; 49 dataIn.readFully(data); 50 return wireFormat.unmarshal(new ByteSequence(data)); 51 } 52 } 53 | Popular Tags |