Skip to content

Commit

Permalink
Switch to R::serializeToRaw() and R::unserializeFromRaw()
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Oct 20, 2024
1 parent 42934b1 commit 281f18b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/Redis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class Redis {
std::string set(std::string key, SEXP s) {

// if raw, use as is else serialize to raw
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : serializeToRaw(s);
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : R::serializeToRaw(s);

// uses binary protocol, see hiredis doc at github
redisReply *reply =
Expand All @@ -271,7 +271,7 @@ class Redis {
int nc = reply->len;
Rcpp::RawVector res(nc);
memcpy(res.begin(), reply->str, nc);
obj = unserializeFromRaw(res);
obj = R::unserializeFromRaw(res);
}
freeReplyObject(reply);
return(obj);
Expand All @@ -281,7 +281,7 @@ class Redis {
int hset(std::string key, std::string field, SEXP s) {

// if raw, use as is else serialize to raw
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : serializeToRaw(s);
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : R::serializeToRaw(s);

// uses binary protocol, see hiredis doc at github
redisReply *reply =
Expand All @@ -305,7 +305,7 @@ class Redis {
Rcpp::RawVector res(nc);
memcpy(res.begin(), reply->str, nc);
freeReplyObject(reply);
SEXP obj = unserializeFromRaw(res);
SEXP obj = R::unserializeFromRaw(res);
return(obj);
}

Expand Down Expand Up @@ -379,7 +379,7 @@ class Redis {
int vlen = reply->element[valueidx]->len;
Rcpp::RawVector res(vlen);
memcpy(res.begin(), reply->element[valueidx]->str, vlen);
SEXP obj = unserializeFromRaw(res);
SEXP obj = R::unserializeFromRaw(res);
vec[i] = obj;
}
vec.names() = keys;
Expand All @@ -391,7 +391,7 @@ class Redis {
SEXP sadd(std::string key, SEXP s) {

// if raw, use as is else serialize to raw
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : serializeToRaw(s);
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : R::serializeToRaw(s);
const char* cmdv[3] = {"SADD", key.c_str(), reinterpret_cast<char*>(x.begin())};
size_t cmdlen[3] = {4, key.length(), static_cast<size_t>(x.size())};

Expand All @@ -407,7 +407,7 @@ class Redis {
SEXP srem(std::string key, SEXP s) {

// if raw, use as is else serialize to raw
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : serializeToRaw(s);
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : R::serializeToRaw(s);
const char* cmdv[3] = {"SREM", key.c_str(), reinterpret_cast<char*>(x.begin())};
size_t cmdlen[3] = {4, key.length(), static_cast<size_t>(x.size())};

Expand All @@ -431,7 +431,7 @@ class Redis {
int nc = reply->element[i]->len;
Rcpp::RawVector res(nc);
memcpy(res.begin(), reply->element[i]->str, nc);
SEXP obj = unserializeFromRaw(res);
SEXP obj = R::unserializeFromRaw(res);
x[i] = obj;
}

Expand Down Expand Up @@ -479,7 +479,7 @@ class Redis {
int nc = reply->element[i]->len;
Rcpp::RawVector res(nc);
memcpy(res.begin(), reply->element[i]->str, nc);
SEXP obj = unserializeFromRaw(res);
SEXP obj = R::unserializeFromRaw(res);
x[i] = obj;
}

Expand Down Expand Up @@ -513,7 +513,7 @@ class Redis {
int nc = reply->len;
Rcpp::RawVector res(nc);
memcpy(res.begin(), reply->str, nc);
obj = unserializeFromRaw(res);
obj = R::unserializeFromRaw(res);
}

return(obj);
Expand Down Expand Up @@ -543,7 +543,7 @@ class Redis {
SEXP lpush(std::string key, SEXP s) {

// if raw, use as is else serialize to raw
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : serializeToRaw(s);
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : R::serializeToRaw(s);

// uses binary protocol, see hiredis doc at github
redisReply *reply =
Expand All @@ -561,7 +561,7 @@ class Redis {
SEXP rpush(std::string key, SEXP s) {

// if raw, use as is else serialize to raw
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : serializeToRaw(s);
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : R::serializeToRaw(s);

// uses binary protocol, see hiredis doc at github
redisReply *reply =
Expand Down Expand Up @@ -939,17 +939,17 @@ class Redis {
vec[i] = extract_reply(reply->element[i]);
} else
{
if(type == "string") {
if (type == "string") {
vec[i] = Rcpp::wrap(std::string(reply->element[i]->str));
goto end;
}
int vlen = reply->element[i]->len;
Rcpp::RawVector res(vlen);
memcpy(res.begin(), reply->element[i]->str, vlen);
if(type == "raw") {
if (type == "raw") {
vec[i] = res;
} else {
vec[i] = unserializeFromRaw(res);
vec[i] = R::unserializeFromRaw(res);
}
}
}
Expand Down Expand Up @@ -995,7 +995,7 @@ class Redis {
SEXP publish(std::string channel, SEXP s) {

// if raw, use as is else serialize to raw
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : serializeToRaw(s);
Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : R::serializeToRaw(s);

// uses binary protocol, see hiredis doc at github
redisReply *reply =
Expand Down

0 comments on commit 281f18b

Please sign in to comment.