fixed checking for proto parsing errors

Former-commit-id: 7831e93bf6c65e574b185d30856af096171b43ac
This commit is contained in:
johan 2013-10-13 17:58:41 +02:00
parent 6db1db3129
commit 91dcbd0758

View File

@ -61,13 +61,9 @@ void ProtoClientConnection::readData()
// read a message // read a message
proto::HyperionRequest message; proto::HyperionRequest message;
try if (!message.ParseFromArray(_receiveBuffer.data() + 4, messageSize))
{ {
message.ParseFromArray(_receiveBuffer.data() + 4, messageSize); sendErrorReply("Unable to parse message");
}
catch(const std::exception & e)
{
sendErrorReply(std::string("Unable to parse message: ") + e.what());
} }
// handle the message // handle the message
@ -203,7 +199,6 @@ void ProtoClientConnection::sendMessage(const google::protobuf::Message &message
std::string serializedReply = message.SerializeAsString(); std::string serializedReply = message.SerializeAsString();
uint32_t size = serializedReply.size(); uint32_t size = serializedReply.size();
uint8_t sizeData[] = {uint8_t(size >> 24), uint8_t(size >> 16), uint8_t(size >> 8), uint8_t(size)}; uint8_t sizeData[] = {uint8_t(size >> 24), uint8_t(size >> 16), uint8_t(size >> 8), uint8_t(size)};
std::cout << sizeData[0] << " " << sizeData[0] << " " << sizeData[0] << " " << sizeData[0] << " <data>" << std::endl;
_socket->write((const char *) sizeData, sizeof(sizeData)); _socket->write((const char *) sizeData, sizeof(sizeData));
_socket->write(serializedReply.data(), serializedReply.length()); _socket->write(serializedReply.data(), serializedReply.length());
_socket->flush(); _socket->flush();