feat: Support table view for C client.#294
Conversation
|
In addition, I don't think use a null-terminated string as the tableview value is good for C API. The value is actually a byte array rather than a null-terminated string. Unlike the #include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void get_value(char **value) {
char *data = (char *)malloc(4);
data[0] = 0x01;
data[1] = 0x00;
data[2] = 0x02;
data[3] = 0x00;
*value = data;
}
int main(int argc, char *argv[]) {
char *value;
get_value(&value);
printf("length: %zu\n", strlen(value));
return 0;
}The code example is a demo to show the difference between a byte array and a null-terminated string. So it's better to add a length parameter like: #include <stdio.h>
#include <stdlib.h>
static void get_value(char **value_ptr, size_t *value_len) {
char *data = (char *)malloc(4);
data[0] = 0x01;
data[1] = 0x00;
data[2] = 0x02;
data[3] = 0x00;
*value_ptr = data;
*value_len = 4;
}
int main(int argc, char *argv[]) {
char *value;
size_t len;
get_value(&value, &len);
printf("length: %zu\n", len);
for (size_t i = 0; i < len; i++) {
printf("0x%02x%c", value[i], (i < len - 1) ? ' ' : '\n');
}
return 0;
}Output: |
Thanks explain, that makes sense to me. New commit modifications:
PTAL. |
BewareMyPower
left a comment
There was a problem hiding this comment.
LGTM except the example is still wrong.
Motivation
Support table view for C client.
Modifications
Verifying this change
Documentation
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
doc(Your PR contains doc changes)
doc-complete(Docs have been already added)