-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Producer/Consumer table binary support #801
Conversation
Signed-off-by: Ze Gan <[email protected]>
Signed-off-by: Ze Gan <[email protected]>
Signed-off-by: Ze Gan <[email protected]>
Signed-off-by: Ze Gan <[email protected]>
Signed-off-by: Ze Gan <[email protected]>
d694c72
to
466a131
Compare
I see a common pattern when using this function. Better to create an overload function, and keep this as is.
In reply to: 1612539336 In reply to: 1612539336 In reply to: 1612539336 Refers to: common/rediscommand.cpp:39 in 466a131. [](commit_id = 466a131, deletion_comment = False) |
98be4ca
to
837e19d
Compare
Signed-off-by: Ze Gan <[email protected]>
837e19d
to
bcf697e
Compare
I found an existing API, |
common/redisstring.h
Outdated
|
||
void reset(char *str = nullptr, int len = 0); | ||
|
||
const char *getStr() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -124,12 +113,12 @@ void RedisCommand::formatDEL(const std::string& key) | |||
|
|||
const char *RedisCommand::c_str() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
- Because we have already provided the function
len
to get the length, so\0
will be handled. - As the STL string's convention,
const char *
doesn't matter to the `\0'. - If we don't expose the
const char *
instead of expose astd::string
, which is safer but MAY introduce one extra deep copy which is unnecessary.
This reverts commit bcf697e.
6d60c8b
to
403c6a1
Compare
Signed-off-by: Ze Gan <[email protected]>
403c6a1
to
142c060
Compare
common/rediscommand.h
Outdated
@@ -64,12 +66,17 @@ class RedisCommand { | |||
/* Format DEL key command */ | |||
void formatDEL(const std::string& key); | |||
|
|||
int appendTo(redisContext *ctx) const; | |||
|
|||
std::string printable_string() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or if you think the semantics are different, you may follow the function naming convention toPrintableString
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -166,4 +166,61 @@ static inline std::string binary_to_hex(const void *buffer, size_t length) | |||
return s; | |||
} | |||
|
|||
static inline std::string binary_to_printable(const void *buffer, size_t length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common/rediscommand.h
Outdated
|
||
std::string printable_string() const; | ||
|
||
private: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not available, because functions, c_str and len, have been used in other functions of this class.
53171aa
to
e73f7ad
Compare
Signed-off-by: Ze Gan <[email protected]>
e73f7ad
to
35f70ec
Compare
Signed-off-by: Ze Gan <[email protected]>
Signed-off-by: Ze Gan <[email protected]>
f4db021
to
9370b19
Compare
PR sonic-net#801 added some code to convert binary strings to be printable strings. However, one code path used the raw value of `len` without sanity checking as the length of the string, when the `length()` function should have been used instead. Sample syncd backtrace: ``` (gdb) print *this $22 = {temp = 0x55feeaced250 "*3\r\n$6\r\nSCRIPT\r\n$4\r\nLOAD\r\n$863\r\nlocal keys = redis.call('KEYS', KEYS[1])\nlocal n = table.getn(keys)\n\nfor i = 1, n do\n if KEYS[2] == \"\" and KEYS[3] == \"1\" then\n redis.call('DEL', keys[i]) \n e"..., len = -355539936} ``` Fix this by using the `length()` function. Signed-off-by: Saikrishna Arcot <[email protected]>
We want to make the Producer/Consumer table can support binary messages, The native C string (char *) will be replaced to pointers and its lengths in all paths. Meanwhile, the Python interfaces of SWIG can only handle the type, str, with UTF-8. So, we need to specialize the SWIG interfaces from bytes of Python to string of C++. --------- Signed-off-by: Ze Gan <[email protected]> Co-authored-by: Qi Luo <[email protected]>
We want to make the Producer/Consumer table can support binary messages, The native C string (char *) will be replaced to pointers and its lengths in all paths.
Meanwhile, the Python interfaces of SWIG can only handle the type, str, with UTF-8. So, we need to specialize the SWIG interfaces from bytes of Python to string of C++.