rbtree和hash的全量持久化操作。rbtree的二进制安全。
粗略测试。
This commit is contained in:
@@ -65,7 +65,7 @@ int kvs_write_u32(uint8_t **pp, const uint8_t *end, uint32_t v) {
|
||||
|
||||
|
||||
|
||||
int getcmd(uint8_t op, const char *key, const char *value, uint8_t *buf){
|
||||
int getcmd(uint8_t op, const char *key, uint32_t key_len, const char *value, uint32_t value_len, uint8_t *buf){
|
||||
if(!buf) return -1;
|
||||
uint8_t *end = buf + CMD_SIZE;
|
||||
uint8_t *p = buf;
|
||||
@@ -79,7 +79,7 @@ int getcmd(uint8_t op, const char *key, const char *value, uint8_t *buf){
|
||||
|
||||
// 写入 key
|
||||
if(key){
|
||||
int keylen = strlen(key);
|
||||
int keylen = key_len;
|
||||
if (kvs_write_u32(&p, end, keylen) < 0) return -1;
|
||||
if (kvs_need(p, end, keylen) < 0) return -1;
|
||||
if (keylen > 0) {
|
||||
@@ -89,7 +89,7 @@ int getcmd(uint8_t op, const char *key, const char *value, uint8_t *buf){
|
||||
}
|
||||
|
||||
if(value){
|
||||
int vallen = strlen(value);
|
||||
int vallen = value_len;
|
||||
if (kvs_write_u32(&p, end, vallen) < 0) return -1;
|
||||
if (kvs_need(p, end, vallen) < 0) return -1;
|
||||
if (vallen > 0) {
|
||||
@@ -102,6 +102,7 @@ int getcmd(uint8_t op, const char *key, const char *value, uint8_t *buf){
|
||||
}
|
||||
|
||||
int parse_response(const uint8_t *buf, int buflen, kvs_response_t *rsp) {
|
||||
if(buflen == 0) return 0;
|
||||
const uint8_t *p = buf;
|
||||
const uint8_t *end = buf + buflen;
|
||||
|
||||
@@ -139,7 +140,7 @@ int parse_response(const uint8_t *buf, int buflen, kvs_response_t *rsp) {
|
||||
|
||||
void print_response(const char *cmd_name, const kvs_response_t *rsp) {
|
||||
printf("%s ", cmd_name);
|
||||
if(rsp->op == KVS_CMD_GET){
|
||||
if(rsp->op == KVS_CMD_GET || rsp->op == KVS_CMD_HGET || rsp->op == KVS_CMD_RGET){
|
||||
if (rsp->datalen > 0 && rsp->data != NULL) {
|
||||
printf("Data: ");
|
||||
// 尝试以字符串形式打印(如果是可打印字符)
|
||||
@@ -190,7 +191,7 @@ void print_response(const char *cmd_name, const kvs_response_t *rsp) {
|
||||
}
|
||||
|
||||
int verify_response(const kvs_response_t *rsp, uint8_t expected_op,
|
||||
uint8_t expected_status, const char *expected_data) {
|
||||
uint8_t expected_status, const char *expected_data, uint32_t expected_len) {
|
||||
if (rsp->op != expected_op) {
|
||||
printf("❌ OP mismatch: expected %u, got %u\n", expected_op, rsp->op);
|
||||
return 0;
|
||||
@@ -202,7 +203,6 @@ int verify_response(const kvs_response_t *rsp, uint8_t expected_op,
|
||||
}
|
||||
|
||||
if (expected_data != NULL) {
|
||||
uint32_t expected_len = strlen(expected_data);
|
||||
if (rsp->datalen != expected_len) {
|
||||
printf("❌ Data length mismatch: expected %u, got %u\n", expected_len, rsp->datalen);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user