Skip to content

Commit 9ca944e

Browse files
miaobyteclaude
andcommitted
fix: tutorial/wrapper 的 xvalue_*/XK_* 改为 kvspaceXvalue*/KVSPACE_KIND_*
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d012c0b commit 9ca944e

4 files changed

Lines changed: 22 additions & 22 deletions

File tree

‎tutorial/01_basic.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929
static void get(kvspace_t *kv, const char *key) {
3030
int32_t len; uint8_t *v = kvspaceShmGet(kv, key, 1, &len);
3131
if (!v || len == 0) { printf("%s\t(nil)\n", key); return; }
32-
xvalue_head_t h = xvalue_decode_head(v, len);
32+
xvalue_head_t h = kvspaceXvalueDecodeHead(v, len);
3333
printf("%s\t%.*s:", key, h.kind_len, h.kind);
3434
if (h.raw_len > 0) {
35-
if (strncmp(h.kind, XK_INT64, h.kind_len) == 0) printf("%ld", xvalue_at_int64(&h, 0));
36-
else if (strncmp(h.kind, XK_STRING, h.kind_len) == 0) printf("%.*s", h.raw_len, h.raw);
37-
else if (strncmp(h.kind, XK_FLOAT64, h.kind_len) == 0) printf("%.2f", xvalue_at_float64(&h, 0));
35+
if (strncmp(h.kind, KVSPACE_KIND_INT64, h.kind_len) == 0) printf("%ld", kvspaceXvalueAtInt64(&h, 0));
36+
else if (strncmp(h.kind, KVSPACE_KIND_CHAR, h.kind_len) == 0) printf("%.*s", h.raw_len, h.raw);
37+
else if (strncmp(h.kind, KVSPACE_KIND_FLOAT64, h.kind_len) == 0) printf("%.2f", kvspaceXvalueAtFloat64(&h, 0));
3838
}
3939
printf("\n");
4040
free(v);
4141
}
4242

4343
static void set_int(kvspace_t *kv, const char *key, int64_t v) {
44-
uint8_t *b; int32_t bl = xvalue_new_int64_1(v, &b);
44+
uint8_t *b; int32_t bl = kvspaceXvalueNewInt641(v, &b);
4545
kvspaceShmSet(kv, key, b, bl); free(b);
4646
}
4747
static void set_str(kvspace_t *kv, const char *key, const char *v) {
48-
uint8_t *b; int32_t bl = xvalue_new_char(v, &b);
48+
uint8_t *b; int32_t bl = kvspaceXvalueNewChar(v, &b);
4949
kvspaceShmSet(kv, key, b, bl); free(b);
5050
}
5151
static void list(kvspace_t *kv, const char *dir, bool show_kind) {
@@ -56,10 +56,10 @@ static void list(kvspace_t *kv, const char *dir, bool show_kind) {
5656
sprintf(k, "%s%s", dir, ns[i]);
5757
if (show_kind) {
5858
int32_t len; uint8_t *v = kvspaceShmGet(kv, k, 1, &len);
59-
if (v) { xvalue_head_t h = xvalue_decode_head(v, len);
59+
if (v) { xvalue_head_t h = kvspaceXvalueDecodeHead(v, len);
6060
printf("%s\t%.*s", ns[i], h.kind_len, h.kind);
61-
if (h.raw_len > 0 && strncmp(h.kind, XK_INT64, h.kind_len) == 0)
62-
printf("\t%ld", xvalue_at_int64(&h, 0));
61+
if (h.raw_len > 0 && strncmp(h.kind, KVSPACE_KIND_INT64, h.kind_len) == 0)
62+
printf("\t%ld", kvspaceXvalueAtInt64(&h, 0));
6363
printf("\n"); free(v);
6464
}
6565
} else {

‎tutorial/02_cpp.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct KV {
3232
bool get(const char *key, std::string &kind, std::string &raw) {
3333
int32_t len; uint8_t *v = kvspaceShmGet(kv, key, 1, &len);
3434
if (!v) return false;
35-
xvalue_head_t h = xvalue_decode_head(v, len);
35+
xvalue_head_t h = kvspaceXvalueDecodeHead(v, len);
3636
kind.assign(h.kind, h.kind_len);
3737
raw.assign((const char *)h.raw, h.raw_len);
3838
free(v);

‎tutorial/05_integrity.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ static uint8_t *encode_bytes(const uint8_t *raw, int32_t rl, int32_t *len) {
4646
static bool check(kvspace_t *kv, const char *key, int64_t expected, int round) {
4747
int32_t len; uint8_t *v = kvspaceShmGet(kv, key, 1, &len);
4848
if (!v) { printf("ROUND%d MISS %s\n", round, key); return false; }
49-
xvalue_head_t h = xvalue_decode_head(v, len);
50-
if (h.raw_len < 8 || strncmp(h.kind, XK_INT64, h.kind_len) != 0) {
49+
xvalue_head_t h = kvspaceXvalueDecodeHead(v, len);
50+
if (h.raw_len < 8 || strncmp(h.kind, KVSPACE_KIND_INT64, h.kind_len) != 0) {
5151
printf("ROUND%d CORRUPT %s: bad kind=%.*s raw_len=%d\n", round, key, h.kind_len, h.kind, h.raw_len);
5252
free(v); return false;
5353
}
54-
int64_t got = xvalue_at_int64(&h, 0);
54+
int64_t got = kvspaceXvalueAtInt64(&h, 0);
5555
if (got != expected) {
5656
printf("ROUND%d MISMATCH %s: got=%ld expected=%ld\n", round, key, got, expected);
5757
free(v); return false;
@@ -63,8 +63,8 @@ static bool check(kvspace_t *kv, const char *key, int64_t expected, int round) {
6363
static bool check_str(kvspace_t *kv, const char *key, const char *expected, int round) {
6464
int32_t len; uint8_t *v = kvspaceShmGet(kv, key, 1, &len);
6565
if (!v) { printf("ROUND%d MISS %s\n", round, key); return false; }
66-
xvalue_head_t h = xvalue_decode_head(v, len);
67-
if (strncmp(h.kind, XK_STRING, h.kind_len) != 0) {
66+
xvalue_head_t h = kvspaceXvalueDecodeHead(v, len);
67+
if (strncmp(h.kind, KVSPACE_KIND_CHAR, h.kind_len) != 0) {
6868
printf("ROUND%d CORRUPT %s: bad kind\n", round, key); free(v); return false;
6969
}
7070
if (h.raw_len != (int32_t)strlen(expected) || memcmp(h.raw, expected, h.raw_len) != 0) {
@@ -183,7 +183,7 @@ int main() {
183183
char k[64]; snprintf(k, sizeof(k), "/it/big%d", i);
184184
int32_t len; uint8_t *v = kvspaceShmGet(kv, k, 1, &len);
185185
if (!v) { printf("ROUND5 MISS big%d\n", i); errors++; continue; }
186-
xvalue_head_t h = xvalue_decode_head(v, len);
186+
xvalue_head_t h = kvspaceXvalueDecodeHead(v, len);
187187
if (h.raw_len != MAX_VAL_SZ || memcmp(h.raw, big_vals[i], MAX_VAL_SZ) != 0) {
188188
printf("ROUND5 CORRUPT big%d\n", i); errors++;
189189
}

‎tutorial/06_multiprocess.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ static int reader(kvspace_t *kv, int64_t seed) {
101101
int64_t expected = ((int64_t)rand() << 32) | rand();
102102
int32_t l; uint8_t *v = kvspaceShmGet(kv, k, 1, &l);
103103
if (v) {
104-
xvalue_head_t h = xvalue_decode_head(v, l);
105-
if (h.raw_len >= 8 && strncmp(h.kind, XK_INT64, h.kind_len) == 0) {
106-
int64_t got = xvalue_at_int64(&h, 0);
104+
xvalue_head_t h = kvspaceXvalueDecodeHead(v, l);
105+
if (h.raw_len >= 8 && strncmp(h.kind, KVSPACE_KIND_INT64, h.kind_len) == 0) {
106+
int64_t got = kvspaceXvalueAtInt64(&h, 0);
107107
if (got != expected) {
108108
printf("[reader] MISMATCH %s: got=%ld expected=%ld\n", k, got, expected);
109109
errors++;
@@ -121,8 +121,8 @@ static int reader(kvspace_t *kv, int64_t seed) {
121121
char k[64]; snprintf(k, sizeof(k), "/mp/s%d", i);
122122
int32_t l; uint8_t *v = kvspaceShmGet(kv, k, 1, &l);
123123
if (!v) continue; // may have been overwritten
124-
xvalue_head_t h = xvalue_decode_head(v, l);
125-
if (strncmp(h.kind, XK_STRING, h.kind_len) != 0) {
124+
xvalue_head_t h = kvspaceXvalueDecodeHead(v, l);
125+
if (strncmp(h.kind, KVSPACE_KIND_CHAR, h.kind_len) != 0) {
126126
printf("[reader] BADKIND %s: %.*s\n", k, h.kind_len, h.kind); errors++;
127127
}
128128
free(v);
@@ -136,7 +136,7 @@ static int reader(kvspace_t *kv, int64_t seed) {
136136
char k[64]; snprintf(k, sizeof(k), "/mp/big%d", i);
137137
int32_t l; uint8_t *v = kvspaceShmGet(kv, k, 1, &l);
138138
if (v) {
139-
xvalue_head_t h = xvalue_decode_head(v, l);
139+
xvalue_head_t h = kvspaceXvalueDecodeHead(v, l);
140140
if (h.raw_len == 1024) big_ok++;
141141
free(v);
142142
}

0 commit comments

Comments
 (0)