BewareMyPower commented on code in PR #17125:
URL: https://github.com/apache/pulsar/pull/17125#discussion_r976005909


##########
pulsar-client-cpp/lib/Schema.cc:
##########
@@ -90,6 +131,43 @@ SchemaInfo::SchemaInfo(SchemaType schemaType, const 
std::string &name, const std
                        const StringMap &properties)
     : impl_(std::make_shared<SchemaInfoImpl>(schemaType, name, schema, 
properties)) {}
 
+SchemaInfo::SchemaInfo(const SchemaInfo &keySchema, const SchemaInfo 
&valueSchema,
+                       const KeyValueEncodingType &keyValueEncodingType) {
+    std::string keySchemaStr = keySchema.getSchema();
+    std::string valueSchemaStr = valueSchema.getSchema();
+    int keySize = keySchemaStr.size();
+    int valueSize = valueSchemaStr.size();
+
+    int buffSize = sizeof keySize + keySize + sizeof valueSize + valueSize;
+    SharedBuffer buffer = SharedBuffer::allocate(buffSize);
+    buffer.writeUnsignedInt(keySize == 0 ? -1 : keySize);
+    buffer.write(keySchemaStr.c_str(), keySize);
+    buffer.writeUnsignedInt(valueSize == 0 ? -1 : valueSize);
+    buffer.write(valueSchemaStr.c_str(), valueSize);

Review Comment:
   ```suggestion
       buffer.write(keySchemaStr.c_str(), static_cast<uint32_t>(keySize));
       buffer.writeUnsignedInt(valueSize == 0 ? -1 : valueSize);
       buffer.write(valueSchemaStr.c_str(), static_cast<uint32_t>(valueSize));
   ```



##########
pulsar-client-cpp/lib/Schema.cc:
##########
@@ -90,6 +131,43 @@ SchemaInfo::SchemaInfo(SchemaType schemaType, const 
std::string &name, const std
                        const StringMap &properties)
     : impl_(std::make_shared<SchemaInfoImpl>(schemaType, name, schema, 
properties)) {}
 
+SchemaInfo::SchemaInfo(const SchemaInfo &keySchema, const SchemaInfo 
&valueSchema,
+                       const KeyValueEncodingType &keyValueEncodingType) {
+    std::string keySchemaStr = keySchema.getSchema();
+    std::string valueSchemaStr = valueSchema.getSchema();
+    int keySize = keySchemaStr.size();
+    int valueSize = valueSchemaStr.size();
+
+    int buffSize = sizeof keySize + keySize + sizeof valueSize + valueSize;

Review Comment:
   ```suggestion
       size_t keySize = keySchemaStr.size();
       size_t valueSize = valueSchemaStr.size();
   
       size_t buffSize = sizeof keySize + keySize + sizeof valueSize + 
valueSize;
   ```
   
   or use `auto`. In C++, conversion between unsigned and signed integers might 
cause some potential bugs. If the conversion cannot be avoided, we'd better use 
`static_cast` to mark the conversion explicitly.



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