forked from logicalclocks/rondis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.cc
43 lines (38 loc) · 969 Bytes
/
common.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdarg.h>
#include "pink/include/redis_conn.h"
#include <ndbapi/NdbApi.hpp>
#include <ndbapi/Ndb.hpp>
#include "common.h"
void assign_ndb_err_to_response(
std::string *response,
const char *app_str,
NdbError error)
{
char buf[512];
snprintf(buf, sizeof(buf), "-ERR %s; NDB(%u) %s\r\n", app_str, error.code, error.message);
std::cout << buf;
response->assign(buf);
}
void assign_generic_err_to_response(
std::string *response,
const char *app_str)
{
char buf[512];
snprintf(buf, sizeof(buf), "-ERR %s\r\n", app_str);
std::cout << buf;
response->assign(buf);
}
void set_length(char *buf, Uint32 key_len)
{
Uint8 *ptr = (Uint8 *)buf;
ptr[0] = (Uint8)(key_len & 255);
ptr[1] = (Uint8)(key_len >> 8);
}
Uint32 get_length(char *buf)
{
Uint8 *ptr = (Uint8 *)buf;
Uint8 low = ptr[0];
Uint8 high = ptr[1];
Uint32 len32 = Uint32(low) + Uint32(256) * Uint32(high);
return len32;
}