Search in sources :

Example 16 with MessageIdData

use of org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData in project incubator-pulsar by apache.

the class RawMessageImpl method deserializeFrom.

public static RawMessage deserializeFrom(ByteBuf buffer) {
    try {
        int idSize = buffer.readInt();
        int writerIndex = buffer.writerIndex();
        buffer.writerIndex(buffer.readerIndex() + idSize);
        ByteBufCodedInputStream stream = ByteBufCodedInputStream.get(buffer);
        MessageIdData.Builder builder = MessageIdData.newBuilder();
        MessageIdData id = builder.mergeFrom(stream, null).build();
        buffer.writerIndex(writerIndex);
        builder.recycle();
        int payloadAndMetadataSize = buffer.readInt();
        ByteBuf metadataAndPayload = buffer.slice(buffer.readerIndex(), payloadAndMetadataSize);
        return new RawMessageImpl(id, metadataAndPayload);
    } catch (IOException e) {
        // This is in-memory deserialization, should not fail
        log.error("IO exception deserializing ByteBuf (this shouldn't happen as operation is in-memory)", e);
        throw new RuntimeException(e);
    }
}
Also used : MessageIdData(org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData) ByteBufCodedInputStream(org.apache.pulsar.common.util.protobuf.ByteBufCodedInputStream) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

MessageIdData (org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData)16 ByteBuf (io.netty.buffer.ByteBuf)10 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)7 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 InitialPosition (org.apache.pulsar.common.api.proto.PulsarApi.CommandSubscribe.InitialPosition)3 Collections (java.util.Collections)2 Map (java.util.Map)2 Cleanup (lombok.Cleanup)2 BookKeeper (org.apache.bookkeeper.client.BookKeeper)2 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)2 Position (org.apache.bookkeeper.mledger.Position)2 Pair (org.apache.commons.lang3.tuple.Pair)2 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)2 RawMessage (org.apache.pulsar.client.api.RawMessage)2 CommandCloseConsumer (org.apache.pulsar.common.api.proto.PulsarApi.CommandCloseConsumer)2 Test (org.testng.annotations.Test)2