use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.
the class ChunkMessageIdImpl method toByteArray.
@Override
public byte[] toByteArray() {
// write last chunk message id
MessageIdData msgId = super.writeMessageIdData(null, -1, 0);
// write first chunk message id
msgId.setFirstChunkMessageId();
firstChunkMsgId.writeMessageIdData(msgId.getFirstChunkMessageId(), -1, 0);
int size = msgId.getSerializedSize();
ByteBuf serialized = Unpooled.buffer(size, size);
msgId.writeTo(serialized);
return serialized.array();
}
use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.
the class MessageIdImpl method fromByteArrayWithTopic.
public static MessageId fromByteArrayWithTopic(byte[] data, TopicName topicName) throws IOException {
Objects.requireNonNull(data);
MessageIdData idData = LOCAL_MESSAGE_ID.get();
try {
idData.parseFrom(Unpooled.wrappedBuffer(data, 0, data.length), data.length);
} catch (Exception e) {
throw new IOException(e);
}
MessageId messageId;
if (idData.hasBatchIndex()) {
messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex(), idData.getBatchSize(), BatchMessageAcker.newAcker(idData.getBatchSize()));
} else {
messageId = new MessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition());
}
if (idData.getPartition() > -1 && topicName != null) {
messageId = new TopicMessageIdImpl(topicName.getPartition(idData.getPartition()).toString(), topicName.toString(), messageId);
}
return messageId;
}
use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.
the class Commands method newAck.
public static ByteBuf newAck(long consumerId, long ledgerId, long entryId, BitSetRecyclable ackSet, AckType ackType, ValidationError validationError, Map<String, Long> properties, long txnIdLeastBits, long txnIdMostBits, long requestId, int batchSize) {
BaseCommand cmd = localCmd(Type.ACK);
CommandAck ack = cmd.setAck().setConsumerId(consumerId).setAckType(ackType);
MessageIdData messageIdData = ack.addMessageId().setLedgerId(ledgerId).setEntryId(entryId);
if (ackSet != null) {
long[] as = ackSet.toLongArray();
for (int i = 0; i < as.length; i++) {
messageIdData.addAckSet(as[i]);
}
}
if (batchSize >= 0) {
messageIdData.setBatchSize(batchSize);
}
if (validationError != null) {
ack.setValidationError(validationError);
}
if (txnIdMostBits >= 0) {
ack.setTxnidMostBits(txnIdMostBits);
}
if (txnIdLeastBits >= 0) {
ack.setTxnidLeastBits(txnIdLeastBits);
}
if (requestId >= 0) {
ack.setRequestId(requestId);
}
if (!properties.isEmpty()) {
properties.forEach((k, v) -> {
ack.addProperty().setKey(k).setValue(v);
});
}
return serializeWithSize(cmd);
}
use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.
the class RawMessageImpl method deserializeFrom.
public static RawMessage deserializeFrom(ByteBuf buffer) {
int idSize = buffer.readInt();
MessageIdData id = new MessageIdData();
id.parseFrom(buffer, idSize);
int payloadAndMetadataSize = buffer.readInt();
ByteBuf metadataAndPayload = buffer.slice(buffer.readerIndex(), payloadAndMetadataSize);
return new RawMessageImpl(id, metadataAndPayload);
}
Aggregations