Skip to content

Commit

Permalink
chore: Remove ReqSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
dranikpg committed Sep 16, 2024
1 parent 93de559 commit e02ed56
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 40 deletions.
11 changes: 4 additions & 7 deletions src/facade/reply_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -847,13 +847,6 @@ void RedisReplyBuilder::SendStringArrInternal(
Send(vec.data(), vec_indx + 1);
}

void ReqSerializer::SendCommand(std::string_view str) {
VLOG(2) << "SendCommand: " << str;

iovec v[] = {IoVec(str), IoVec(kCRLF)};
ec_ = sink_->Write(v, ABSL_ARRAYSIZE(v));
}

void RedisReplyBuilder2Base::SendNull() {
ReplyScope scope(this);
resp3_ ? WritePieces(kNullStringR3) : WritePieces(kNullStringR2);
Expand Down Expand Up @@ -955,6 +948,10 @@ void RedisReplyBuilder2Base::SendVerbatimString(std::string_view str, VerbatimFo
WritePieces(kCRLF);
}

std::string RedisReplyBuilder2Base::SerializeCommand(std::string_view command) {
return string{command} + kCRLF;
}

void RedisReplyBuilder2::SendSimpleStrArr2(const facade::ArgRange& strs) {
ReplyScope scope(this);
StartArray(strs.Size());
Expand Down
22 changes: 3 additions & 19 deletions src/facade/reply_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,11 @@ class RedisReplyBuilder2Base : public SinkReplyBuilder2, public RedisReplyBuilde
void SendError(std::string_view str, std::string_view type = {}) override;
void SendProtocolError(std::string_view str) override;

static char* FormatDouble(double d, char* dest, unsigned len);
virtual void SendVerbatimString(std::string_view str, VerbatimFormat format = TXT) override;

static char* FormatDouble(double d, char* dest, unsigned len);
static std::string SerializeCommand(std::string_view command);

bool IsResp3() const override {
return resp3_;
}
Expand Down Expand Up @@ -489,24 +491,6 @@ class RedisReplyBuilder2 : public RedisReplyBuilder2Base {

// TODO: Remove
void SendMGetResponse(SinkReplyBuilder::MGetResponse resp) override;

static std::string SerializeCommmand(std::string_view cmd);
};

class ReqSerializer {
public:
explicit ReqSerializer(::io::Sink* stream) : sink_(stream) {
}

void SendCommand(std::string_view str);

std::error_code ec() const {
return ec_;
}

private:
::io::Sink* sink_;
std::error_code ec_;
};

} // namespace facade
8 changes: 3 additions & 5 deletions src/server/protocol_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ error_code ProtocolClient::ConnectAndAuth(std::chrono::milliseconds connect_time
} else {
sock_.reset(mythread->CreateSocket());
}
serializer_ = std::make_unique<ReqSerializer>(sock_.get());
} else {
return cntx->GetError();
}
Expand Down Expand Up @@ -385,11 +384,10 @@ bool ProtocolClient::CheckRespFirstTypes(initializer_list<RespExpr::Type> types)
}

error_code ProtocolClient::SendCommand(string_view command) {
serializer_->SendCommand(command);
error_code ec = serializer_->ec();
if (!ec) {
string formatted_command = RedisReplyBuilder2Base::SerializeCommand(command);
auto ec = sock_->Write(io::View(formatted_command));
if (!ec)
TouchIoTime();
}
return ec;
}

Expand Down
5 changes: 0 additions & 5 deletions src/server/protocol_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include <openssl/ssl.h>
#endif

namespace facade {
class ReqSerializer;
}; // namespace facade

namespace dfly {

class Service;
Expand Down Expand Up @@ -117,7 +113,6 @@ class ProtocolClient {
private:
ServerContext server_context_;

std::unique_ptr<facade::ReqSerializer> serializer_;
std::unique_ptr<facade::RedisParser> parser_;
facade::RespVec resp_args_;
base::IoBuf resp_buf_;
Expand Down
4 changes: 0 additions & 4 deletions src/server/replica.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include "server/version.h"
#include "util/fiber_socket_base.h"

namespace facade {
class ReqSerializer;
}; // namespace facade

namespace dfly {

class Service;
Expand Down

0 comments on commit e02ed56

Please sign in to comment.