Context
I am writing an event-driven application server in C++. I want to use google protocol buffers for moving my data. Since the server is event driven, the connection handler API is basically a callback function letting me know when another buffer of N bytes has arrived from the client.
Question
My question as a complete beginner of protobuf is this: is it possible to somehow coax protobuf into accepting the many buffers required to make up one complete message to facilitate a "stream parser" rather than waiting for the whole data to arrive into a temporary buffer first?
In other words i want this:
//Event API. May be called multiple times for each protobuf message
bool data_arrived_from_client(void *buf,size_t len){
my_protobuf.parse_part(buf,len); // THIS IS THE GROSSLY SIMPLIFIED SEMANTIC OF WHAT I WANT
message_size+=len;
if(message_size>COMPLETE_BUFFER_SIZE){
use_complete_protobuf();
return true;
}
return false;
}
..instead of this:
//Event API. May be called multiple times for each protobuf message
bool data_arrived_from_client(void *buf,size_t len){
my_temp_buffer.append_data(buf,len);
message_size+=len;
if(message_size>COMPLETE_BUFFER_SIZE){
my_protobuf.ParseFromArray(my_temp_buffer.data_ptr(),my_temp_buffer.size());
use_complete_protobuf();
return true;
}
return false;
}
Answer
Answers with complete code is especially appreciated!