cetcd icon indicating copy to clipboard operation
cetcd copied to clipboard

can we handle the value contain `\0`?

Open xiaoyulei opened this issue 8 years ago • 6 comments

We try to write key-value pair but the value is binary, contain \0. It can not store all value into etcd.

xiaoyulei avatar Feb 13 '17 04:02 xiaoyulei

cetcd use redis's sds to handle string. It is supported to write binary. Do you have more details?

shafreeck avatar Feb 13 '17 06:02 shafreeck

all the function parameter is char*, like cetcd_set(cetcd_client *cli, const char *key, const char *value, uint64_t ttl) , if we write binary, it will make \0 as end character. value_escaped = curl_easy_escape(cli->curl, value, strlen(value)); strlen will end with \0

xiaoyulei avatar Feb 14 '17 01:02 xiaoyulei

@YuleiXiao In fact, you can pass a cetcd_string as the parameter. It is actually a sds type.

shafreeck avatar Feb 14 '17 03:02 shafreeck

Passing a cetcd_string to cetcd_set() will not solve the problem, since strlen is a libc string function and not a sds function. You have to adjust all string functions in cetcd to only use sds functions and nothing else. This would be a binary incompatible change breaking all existing applications.

thkukuk avatar Feb 14 '17 10:02 thkukuk

@thkukuk Yeah, you are right. I will think about how to support binary safe string

shafreeck avatar Feb 17 '17 05:02 shafreeck

Further more, you can't expect a JSON interface to support binary directly. Just take base64.

eintr avatar May 16 '17 07:05 eintr