C++ REST service module#
-
namespace service#
Namespace including the API Eigen Example Server logic (i.e. service) implemented in C++.
-
class GRPCService : public grpcdemo::GRPCDemo::Service#
Class containing the server logic (i.e. service).
Public Functions
-
GRPCService(const bool debug_log)#
Construct a new GRPCDemo Service object.
- Parameters:
debug_log – whether to show the enhanced debugging logs or not.
-
~GRPCService()#
Destroy the GRPCDemo Service object.
-
::grpc::Status SayHello(::grpc::ServerContext *context, const ::grpcdemo::HelloRequest *request, ::grpcdemo::HelloReply *response) override#
Method to provide a simple greeting to the client.
- Parameters:
context – the gRPC Server context.
request – the gRPC request.
response – the gRPC response this method will fill.
- Returns:
::grpc::Status
-
::grpc::Status FlipVector(::grpc::ServerContext *context, ::grpc::ServerReaderWriter<::grpcdemo::Vector, ::grpcdemo::Vector> *stream) override#
Method to provide a flipped vector to the client.
- Parameters:
context – the gRPC Server context.
stream – the gRPC stream.
- Returns:
::grpc::Status
-
::grpc::Status AddVectors(::grpc::ServerContext *context, ::grpc::ServerReaderWriter<::grpcdemo::Vector, ::grpcdemo::Vector> *stream) override#
Method to provide the addition of Vector messages.
- Parameters:
context – the gRPC Server context.
stream – the gRPC stream.
- Returns:
::grpc::Status
-
::grpc::Status MultiplyVectors(::grpc::ServerContext *context, ::grpc::ServerReaderWriter<::grpcdemo::Vector, ::grpcdemo::Vector> *stream) override#
Method to provide the dot product of Vector messages.
- Parameters:
context – the gRPC Server context.
stream – the gRPC stream.
- Returns:
::grpc::Status
-
::grpc::Status AddMatrices(::grpc::ServerContext *context, ::grpc::ServerReaderWriter<::grpcdemo::Matrix, ::grpcdemo::Matrix> *stream) override#
Method to provide the addition of Matrix messages.
- Parameters:
context – the gRPC Server context.
stream – the gRPC stream.
- Returns:
::grpc::Status
-
::grpc::Status MultiplyMatrices(::grpc::ServerContext *context, ::grpc::ServerReaderWriter<::grpcdemo::Matrix, ::grpcdemo::Matrix> *stream) override#
Method to provide the multiplication of Matrix messages.
- Parameters:
context – the gRPC Server context.
stream – the gRPC stream.
- Returns:
::grpc::Status
Private Functions
-
Eigen::VectorXd deserialize_vector(const std::string &bytes, const int length, grpcdemo::DataType type)#
Method used to deserialize a Vector message into an Eigen::VectorXd object.
- Parameters:
bytes – the chunk of bytes from where the vector is deserialized.
length – the length of the vector we are deserializing.
type – the type of data inside the vector (e.g. double, int…).
- Returns:
Eigen::VectorXd
-
std::string serialize_vector(const Eigen::VectorXd &vector, const int start, const int end)#
Method used to serialize an Eigen::VectorXd object into a Vector message.
- Parameters:
vector – the Eigen::VectorXd to be serialized.
start – the starting index to serialize.
end – the last index to serialize (not included).
- Returns:
std::string
-
Eigen::MatrixXd deserialize_matrix(const std::string &bytes, const int rows, const int cols, grpcdemo::DataType type)#
Method used to deserialize a Matrix message into an Eigen::MatrixXd object.
- Parameters:
bytes – the chunk of bytes from where the matrix is deserialized.
rows – the number of rows of the matrix we are deserializing.
cols – the number of columns of the matrix we are deserializing.
type – the type of data inside the matrix (e.g. double, int…).
- Returns:
Eigen::MatrixXd
-
std::string serialize_matrix(const Eigen::MatrixXd &matrix, const int start, const int end)#
Method used to serialize an Eigen::MatrixXd object into a Matrix message.
- Parameters:
matrix – the Eigen::MatrixXd to be serialized.
start – the starting index to serialize.
end – the last index to serialize (not included).
- Returns:
std::string
-
std::vector<Eigen::VectorXd> receive_vectors(::grpc::ServerReaderWriter<grpcdemo::Vector, grpcdemo::Vector> *reader_writer, ::grpc::ServerContext *context)#
Method in charge of providing a set of Eigen::VectorXd objects from a stream of Vector messages.
- Parameters:
reader_writer – the gRPC reader-writer in the bidirectional stream protocol.
context – the gRPC context.
- Returns:
std::vector<Eigen::VectorXd>
-
std::vector<Eigen::MatrixXd> receive_matrices(::grpc::ServerReaderWriter<grpcdemo::Matrix, grpcdemo::Matrix> *reader_writer, ::grpc::ServerContext *context)#
Method in charge of providing a set of Eigen::MatrixXd objects from a stream of Matrix messages.
- Parameters:
reader_writer – the gRPC reader-writer in the bidirectional stream protocol.
context – the gRPC context.
- Returns:
std::vector<Eigen::MatrixXd>
-
void send_vector(::grpc::ServerReaderWriter<grpcdemo::Vector, grpcdemo::Vector> *reader_writer, ::grpc::ServerContext *context, const Eigen::VectorXd &vector)#
Method in charge of sending the resulting vector of the operation through the protocol.
- Parameters:
reader_writer – the gRPC reader-writer in the bidirectional stream protocol.
context – the gRPC context.
vector – the vector to be sent.
-
void send_matrix(::grpc::ServerReaderWriter<grpcdemo::Matrix, grpcdemo::Matrix> *reader_writer, ::grpc::ServerContext *context, const Eigen::MatrixXd &matrix)#
Method in charge of sending the resulting matrix of the operation through the protocol.
- Parameters:
reader_writer – the gRPC reader-writer in the bidirectional stream protocol.
context – the gRPC context.
matrix – the matrix to be sent.
Private Members
-
bool _debug_log#
Boolean indicating whether to show the debugging logs or not.
-
GRPCService(const bool debug_log)#
-
class GRPCService : public grpcdemo::GRPCDemo::Service#