001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  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 */
017package org.apache.activemq.store.kahadaptor;
018
019import java.io.DataInput;
020import java.io.DataOutput;
021import java.io.IOException;
022import org.apache.activemq.command.MessageId;
023import org.apache.activemq.kaha.Marshaller;
024import org.apache.activemq.kaha.impl.index.IndexItem;
025
026/**
027 * Marshall a TopicSubAck
028 * 
029 * 
030 */
031public class ConsumerMessageRefMarshaller implements Marshaller {
032
033    /**
034     * @param object
035     * @param dataOut
036     * @throws IOException
037     * @see org.apache.activemq.kaha.Marshaller#writePayload(java.lang.Object,
038     *      java.io.DataOutput)
039     */
040    public void writePayload(Object object, DataOutput dataOut) throws IOException {
041        ConsumerMessageRef ref = (ConsumerMessageRef)object;
042        dataOut.writeUTF(ref.getMessageId().toString());
043        IndexItem item = (IndexItem)ref.getMessageEntry();
044        dataOut.writeLong(item.getOffset());
045        item.write(dataOut);
046        item = (IndexItem)ref.getAckEntry();
047        dataOut.writeLong(item.getOffset());
048        item.write(dataOut);
049
050    }
051
052    /**
053     * @param dataIn
054     * @return payload
055     * @throws IOException
056     * @see org.apache.activemq.kaha.Marshaller#readPayload(java.io.DataInput)
057     */
058    public Object readPayload(DataInput dataIn) throws IOException {
059        ConsumerMessageRef ref = new ConsumerMessageRef();
060        ref.setMessageId(new MessageId(dataIn.readUTF()));
061        IndexItem item = new IndexItem();
062        item.setOffset(dataIn.readLong());
063        item.read(dataIn);
064        ref.setMessageEntry(item);
065        item = new IndexItem();
066        item.setOffset(dataIn.readLong());
067        item.read(dataIn);
068        ref.setAckEntry(item);
069        return ref;
070    }
071}