Skip to content

Commit

Permalink
simplify peekOffsetFromEntry (apache#328)
Browse files Browse the repository at this point in the history
simplify `MessageIdUtils.peekOffsetFromEntry` by use `Commands.peekBrokerEntryMetadataIfExist` directly
  • Loading branch information
aloyszhang authored Jan 16, 2021
1 parent feb48c0 commit 051e2b8
Showing 1 changed file with 1 addition and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import static com.google.common.base.Preconditions.checkArgument;

import io.netty.buffer.ByteBuf;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.apache.bookkeeper.mledger.AsyncCallbacks;
Expand All @@ -27,7 +26,6 @@
import org.apache.pulsar.broker.intercept.ManagedLedgerInterceptorImpl;
import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.impl.MessageIdImpl;
import org.apache.pulsar.common.api.proto.PulsarApi;
import org.apache.pulsar.common.protocol.Commands;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -144,16 +142,8 @@ public static PositionImpl getPositionForOffset(ManagedLedger managedLedger, Lon
}
}

public static PulsarApi.BrokerEntryMetadata peekBrokerEntryMetadata(ByteBuf byteBuf) {
final int readerIndex = byteBuf.readerIndex();
PulsarApi.BrokerEntryMetadata entryMetadata =
Commands.parseBrokerEntryMetadataIfExist(byteBuf);
byteBuf.readerIndex(readerIndex);
return entryMetadata;
}

public static long peekOffsetFromEntry(Entry entry) {
return peekBrokerEntryMetadata(entry.getDataBuffer()).getIndex();
return Commands.peekBrokerEntryMetadataIfExist(entry.getDataBuffer()).getIndex();
}

public static long peekBaseOffsetFromEntry(Entry entry) {
Expand Down

0 comments on commit 051e2b8

Please sign in to comment.