I need to transfer the protobuff between nodes. I use cPacket and request for this. Before transferring, I serialize the protobuff, after which I need to apply a conversion to const char* to it, which could make it the value of the cPacket Name field.
But this causes a problem related to the fact that after converting back to a string of bits, the protobuff cannot be deserialized back. As I understand it, this is due to the fact that when serializing the protobuff, the output is a string of bits, the structure of which breaks when using const char*. But are there any other ways to pass the protobuff without errors?
(.c_str() to the serialized string does not work either)
The code where serialization and placement in cPacket
std::string serialized_string;
if (!opencda_message.SerializeToString(&serialized_string)){
EV_INFO << "Failed to serialize " << std::endl;
throw cRuntimeError("Error while serializing file");
}
size_t buffer_size = serialized_string.size() + 1;
char* buffer = new char[buffer_size];
std::copy(serialized_string.begin(), serialized_string.end(), buffer);
buffer[serialized_string.size()] = '\0';
cPacket *packet = new cPacket(buffer);
packet->setByteLength(1024);
request(req, packet, network.get());
Hi!
Could you suggest a solution to the problem:
I need to transfer the protobuff between nodes. I use cPacket and request for this. Before transferring, I serialize the protobuff, after which I need to apply a conversion to const char* to it, which could make it the value of the cPacket Name field.
But this causes a problem related to the fact that after converting back to a string of bits, the protobuff cannot be deserialized back. As I understand it, this is due to the fact that when serializing the protobuff, the output is a string of bits, the structure of which breaks when using const char*. But are there any other ways to pass the protobuff without errors? (.c_str() to the serialized string does not work either)
The code where serialization and placement in cPacket
Thanks in advance for the answer!