BewareMyPower commented on a change in pull request #14604:
URL: https://github.com/apache/pulsar/pull/14604#discussion_r831247228
##########
File path: pulsar-client-cpp/include/pulsar/MessageId.h
##########
@@ -101,9 +106,15 @@ class PULSAR_PUBLIC MessageId {
friend class PulsarWrapper;
friend class PulsarFriend;
friend class NegativeAcksTracker;
+ friend class ProducerImpl;
friend PULSAR_PUBLIC std::ostream& operator<<(std::ostream& s, const
MessageId& messageId);
+ /**
+ * return is this a chunk message id;
Review comment:
```suggestion
* @return true if it's a chunk message id;
```
##########
File path: pulsar-client-cpp/lib/ChunkMessageIdImpl.h
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <memory>
+#include "MessageIdImpl.h"
+
+namespace pulsar {
+
+class MessageIdImpl;
+
+class ChunkMessageIdImpl : public MessageIdImpl, public
std::enable_shared_from_this<ChunkMessageIdImpl> {
+ public:
+ ChunkMessageIdImpl(const MessageIdImpl& firstChunkMsgId, const
MessageIdImpl& lastChunkMsgId)
+ : MessageIdImpl(lastChunkMsgId.partition_, lastChunkMsgId.ledgerId_,
lastChunkMsgId.entryId_,
+ lastChunkMsgId.batchIndex_) {
Review comment:
You can use the default copy constructor.
```c++
: MessageIdImpl(lastChunkMsgId) {
```
##########
File path: pulsar-client-cpp/lib/ChunkMessageIdImpl.h
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <memory>
+#include "MessageIdImpl.h"
+
+namespace pulsar {
+
+class MessageIdImpl;
+
+class ChunkMessageIdImpl : public MessageIdImpl, public
std::enable_shared_from_this<ChunkMessageIdImpl> {
+ public:
+ ChunkMessageIdImpl(const MessageIdImpl& firstChunkMsgId, const
MessageIdImpl& lastChunkMsgId)
+ : MessageIdImpl(lastChunkMsgId.partition_, lastChunkMsgId.ledgerId_,
lastChunkMsgId.entryId_,
+ lastChunkMsgId.batchIndex_) {
+ firstChunkMsgId_ =
+ std::make_shared<MessageIdImpl>(firstChunkMsgId.partition_,
firstChunkMsgId.ledgerId_,
+ firstChunkMsgId.entryId_,
firstChunkMsgId.batchIndex_);
+ }
+
+ ChunkMessageIdImpl(int32_t firstPartition, int64_t firstLedgerId, int64_t
firstEntryId,
+ int32_t firstBatchIndex, int32_t lastPartition, int64_t
lastLedgerId,
+ int64_t lastEntryId, int32_t lastBatchIndex)
+ : MessageIdImpl(lastPartition, lastLedgerId, lastEntryId,
lastBatchIndex) {
+ firstChunkMsgId_ =
+ std::make_shared<MessageIdImpl>(firstPartition, firstLedgerId,
firstEntryId, firstBatchIndex);
+ }
+
+ std::shared_ptr<MessageIdImpl> getFirstChunkMessageIdImpl() { return
firstChunkMsgId_; }
+
+ std::shared_ptr<MessageIdImpl> getLastChunkMessageIdImpl() {
+ return std::dynamic_pointer_cast<MessageIdImpl>(shared_from_this());
+ }
+
+ private:
+ std::shared_ptr<MessageIdImpl> firstChunkMsgId_;
Review comment:
This design is bad in C++, the memory address is not continuous and the
usage of `std::shared_ptr` is not necessary and brings some unnecessary
overhead. A better design is:
```c++
private:
MessageIdImpl firstChunkMsgId_;
```
```c++
const MessageIdImpl& getFirstChunkMessageIdImpl() const {
return static_cast<const MessageIdImpl&>(*this);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]