You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/25 09:38:53 UTC

[GitHub] [pulsar-client-cpp] BewareMyPower commented on a diff in pull request #22: [feat] Support KeyValue Schema.

BewareMyPower commented on code in PR #22:
URL: https://github.com/apache/pulsar-client-cpp/pull/22#discussion_r1004200874


##########
lib/Schema.cc:
##########
@@ -19,16 +19,58 @@
 #include <pulsar/Schema.h>
 #include <pulsar/defines.h>
 
+#include <boost/property_tree/json_parser.hpp>
+#include <boost/property_tree/ptree.hpp>
 #include <iostream>
 #include <map>
 #include <memory>
 
+#include "SharedBuffer.h"
+using boost::property_tree::ptree;
+using boost::property_tree::read_json;
+using boost::property_tree::write_json;
+
 PULSAR_PUBLIC std::ostream &operator<<(std::ostream &s, pulsar::SchemaType schemaType) {
     return s << strSchemaType(schemaType);
 }
 
+PULSAR_PUBLIC std::ostream &operator<<(std::ostream &s, pulsar::KeyValueEncodingType encodingType) {
+    return s << strEncodingType(encodingType);
+}
+
 namespace pulsar {
 
+static const std::string KEY_SCHEMA_NAME = "key.schema.name";
+static const std::string KEY_SCHEMA_TYPE = "key.schema.type";
+static const std::string KEY_SCHEMA_PROPS = "key.schema.properties";
+static const std::string VALUE_SCHEMA_NAME = "value.schema.name";
+static const std::string VALUE_SCHEMA_TYPE = "value.schema.type";
+static const std::string VALUE_SCHEMA_PROPS = "value.schema.properties";
+static const std::string KV_ENCODING_TYPE = "kv.encoding.type";
+
+PULSAR_PUBLIC const char *strEncodingType(KeyValueEncodingType encodingType) {
+    switch (encodingType) {
+        case KeyValueEncodingType::INLINE:
+            return "INLINE";
+        case KeyValueEncodingType::SEPARATED:
+            return "SEPARATED";
+    };
+    // NOTE : Do not add default case in the switch above. In future if we get new cases for
+    // Schema and miss them in the switch above we would like to get notified. Adding
+    // return here to make the compiler happy.
+    return "UnknownSchemaType";
+}
+
+PULSAR_PUBLIC const KeyValueEncodingType enumEncodingType(std::string encodingTypeStr) {

Review Comment:
   ```suggestion
   PULSAR_PUBLIC KeyValueEncodingType enumEncodingType(std::string encodingTypeStr) {
   ```



##########
include/pulsar/Schema.h:
##########
@@ -27,6 +27,27 @@
 
 namespace pulsar {
 
+/**
+ *  Encoding types of supported KeyValueSchema for Pulsar messages.
+ */
+enum class KeyValueEncodingType
+{
+    /**
+     * Key is stored as message key, while value is stored as message payload.
+     */
+    SEPARATED,
+
+    /**
+     * Key and value are stored as message payload.
+     */
+    INLINE
+};
+
+// Return string representation of result code
+PULSAR_PUBLIC const char *strEncodingType(pulsar::KeyValueEncodingType encodingType);
+
+PULSAR_PUBLIC const KeyValueEncodingType enumEncodingType(std::string encodingTypeStr);

Review Comment:
   ```suggestion
   PULSAR_PUBLIC KeyValueEncodingType enumEncodingType(std::string encodingTypeStr);
   ```
   
   Don't return a const value.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org