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/26 01:25:39 UTC

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

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


##########
lib/KeyValueImpl.cc:
##########
@@ -0,0 +1,78 @@
+/**
+ * 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.
+ */
+#include "KeyValueImpl.h"
+
+#include <pulsar/Schema.h>
+
+#include "SharedBuffer.h"
+
+using namespace pulsar;
+
+namespace pulsar {
+
+KeyValueImpl::KeyValueImpl(const char *data, int length, KeyValueEncodingType keyValueEncodingType) {
+    if (keyValueEncodingType == KeyValueEncodingType::INLINE) {
+        SharedBuffer buffer = SharedBuffer::wrap(const_cast<char *>(data), length);
+        auto keySize = buffer.readUnsignedInt();
+        if (keySize != INVALID_SIZE) {
+            SharedBuffer keyContent = buffer.slice(0, keySize);
+            key_ = std::string(keyContent.data(), keySize);
+            buffer.consume(keySize);
+        }
+        auto valueSize = buffer.readUnsignedInt();
+        if (valueSize != INVALID_SIZE) {
+            valueBuffer_ = buffer.slice(0, valueSize);
+        }
+    } else {
+        valueBuffer_ = SharedBuffer::wrap(const_cast<char *>(data), length);
+    }
+}

Review Comment:
   I can't reproduce it on my host. 
   
   ```
   2022-10-26 09:23:37.185 INFO  [0x16fdbb000] ConsumerImpl:231 | [persistent://public/default/test-kv, sub, 0] Created consumer on broker [127.0.0.1:60198 -> 127.0.0.1:6650] 
   2022-10-26 09:23:37.200 INFO  [0x100228580] SampleConsumer:50 | Received KeyValue(key=, value=value) from (1,0,-1,0)
   2022-10-26 09:23:37.200 INFO  [0x100228580] ClientImpl:517 | Closing Pulsar client with 1 producers and 1 consumers
   ```



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