BewareMyPower commented on code in PR #148: URL: https://github.com/apache/pulsar-client-cpp/pull/148#discussion_r1052083840
########## lib/ChunkMessageIdImpl.h: ########## @@ -0,0 +1,46 @@ +/** + * 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 "MessageIdImpl.h" + +namespace pulsar { +class ChunkMessageIdImpl; +typedef std::shared_ptr<ChunkMessageIdImpl> ChunkMessageIdImplPtr; +class ChunkMessageIdImpl : public MessageIdImpl { + public: + ChunkMessageIdImpl() : firstChunkMsgId_(std::make_shared<MessageIdImpl>()) {} + + void setFirstChunkMessageId(const MessageId& msgId) { *firstChunkMsgId_ = *msgId.impl_; } + + void setLastChunkMessageId(const MessageId& msgId) { + this->ledgerId_ = msgId.ledgerId(); + this->entryId_ = msgId.entryId(); + this->partition_ = msgId.partition(); + } + + std::shared_ptr<MessageIdImpl> getFirstChunkMessageId() { return firstChunkMsgId_; } Review Comment: ```suggestion std::shared_ptr<MessageIdImpl> getFirstChunkMessageId() const { return firstChunkMsgId_; } ``` ########## lib/ChunkMessageIdImpl.h: ########## @@ -0,0 +1,46 @@ +/** + * 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 "MessageIdImpl.h" + +namespace pulsar { +class ChunkMessageIdImpl; +typedef std::shared_ptr<ChunkMessageIdImpl> ChunkMessageIdImplPtr; +class ChunkMessageIdImpl : public MessageIdImpl { + public: + ChunkMessageIdImpl() : firstChunkMsgId_(std::make_shared<MessageIdImpl>()) {} + + void setFirstChunkMessageId(const MessageId& msgId) { *firstChunkMsgId_ = *msgId.impl_; } + + void setLastChunkMessageId(const MessageId& msgId) { + this->ledgerId_ = msgId.ledgerId(); + this->entryId_ = msgId.entryId(); + this->partition_ = msgId.partition(); + } + + std::shared_ptr<MessageIdImpl> getFirstChunkMessageId() { return firstChunkMsgId_; } + + static MessageId buildMessageId(const ChunkMessageIdImplPtr& msgIdImpl) { return MessageId{msgIdImpl}; } Review Comment: Instead of the static method, we can just add a non-static method like: ```c++ MessageId build() const { return MessageId{std::dynamic_pointer_cast<MessageIdImpl>( std::const_pointer_cast<ChunkMessageIdImpl>(shared_from_this()))}; } ``` To have `shared_from_this()` method, you should inherit another class: ```c++ class ChunkMessageIdImpl : public MessageIdImpl, public std::enable_shared_from_this<ChunkMessageIdImpl> { ``` Then we can just use `chunkedMsgId->build()` instead of `ChunkedMessageIdImpl::buildMessage(chunkedMsgId);` ########## lib/ChunkMessageIdImpl.h: ########## @@ -0,0 +1,46 @@ +/** + * 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 "MessageIdImpl.h" Review Comment: ```suggestion #include <pulsar/MessageId.h> #include "MessageIdImpl.h" ``` The `MessageIdImpl.h` only includes the `<cstdint>` and `<string>` headers. Thought it doesn't cause the compilation failure because the files that include `ChunkMessageIdImpl.h` all have other necessary headers (like `<memory>` for `std::shared_ptr`) included, but there is a possibility that a new file that includes this header doesn't include these required headers. It could also make same static syntax analysis tool fail. See my Vim:  -- 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]
