BewareMyPower commented on a change in pull request #14604:
URL: https://github.com/apache/pulsar/pull/14604#discussion_r832377612



##########
File path: pulsar-client-cpp/lib/ChunkMessageIdImpl.h
##########
@@ -0,0 +1,44 @@
+/**
+ * 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), firstChunkMsgId_(firstChunkMsgId) {}
+
+    const MessageIdImpl& getFirstChunkMessageIdImpl() { return 
firstChunkMsgId_; }
+
+    std::shared_ptr<MessageIdImpl> getLastChunkMessageIdImplPtr() {
+        return std::dynamic_pointer_cast<MessageIdImpl>(shared_from_this());
+    }

Review comment:
       There is still no need to return a shared pointer here. I see this 
method is used in `MessageId`'s constructor.
   
   ```c++
   impl_ = std::make_shared<ChunkMessageIdImpl>(*firstImpl, 
*lastImpl)->getLastChunkMessageIdImplPtr();
   ```
   
   It's very strange. The type conversion can be performed implicitly. Here is 
an example.
   
   ```c++
   #include <iostream>
   #include <memory>
   using namespace std;
   
   struct Base {
       int x;
   };
   
   struct Derived : Base {
       int y;
       Derived(int xx, int yy) : Base{xx}, y(yy) {}
   };
   
   int main(int argc, char* argv[]) {
       std::shared_ptr<Base> pb = std::make_shared<Derived>(10, 20);
       cout << pb->x << endl;
       cout << std::static_pointer_cast<Derived>(pb)->y << endl;
       return 0;
   }
   ```
   
   




-- 
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]


Reply via email to