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


##########
include/pulsar/c/table_view.h:
##########
@@ -0,0 +1,139 @@
+/**
+ * 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 <pulsar/defines.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <pulsar/c/message.h>
+#include <pulsar/c/messages.h>
+#include <pulsar/c/result.h>
+#include <stdint.h>
+
+typedef struct _pulsar_table_view pulsar_table_view_t;
+
+typedef void (*pulsar_table_view_action)(const char *key, const void *value, 
size_t value_size, void *ctx);
+typedef void (*pulsar_result_callback)(pulsar_result, void *);
+
+/**
+ * Move the latest value associated with the key.
+ *
+ * NOTE:
+ * 1. Once the value has been retrieved successfully,
+ * the associated value will be removed from the table view until next time 
the value is updated.
+ * 2. Once the value has been retrieved successfully, `*value` will point to 
the memory that is allocated
+ * internally. You have to call `free(value)` to free it.
+ *
+ * Example:
+ *
+ * ```c
+ * pulsar_table_view_t *table_view;
+ * char *value;
+ * size_t value_size;
+ * while (true) {
+ *     if (pulsar_table_view_retrieve_value(table_view, "key", &value, 
&value_size)) {
+ *         printf("value is update to: %s", value);

Review Comment:
   You still assumes the `value` is a null-terminated string here. You should 
treat it as a byte array.
   
   ```c
   void* value;
   size_t value_size;
   while (true) {
       if (pulsar_table_view_retrieve_value(table_view, "key", &value, 
&value_size)) {
           for (size_t i = 0; i < value_size; i++) {
               printf("0x%02x%c", ((char*) value)[i], (i + 1 == value_size) ? 
'\n': ' ');
   ```



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