Protocol buffers, Qt and std::string's

891 views
Skip to first unread message

Algirdasss

unread,
Sep 10, 2010, 3:03:33 AM9/10/10
to Protocol Buffers
Hy,

I am using protocol buffers in my current project. I am coding it with
Qt/C++. My application must handle intensive RPC communications
between clients and server. RPC is implemented on the basis of
protocol buffers. Because application internal data structures uses
QString's and QByteArray's, when passing data to protobuf generated
message classes I must accomplish lot of conversions from QString to
std::string. This involves converting and making deep copy of QString
bytes to QByteArray and then another deep copy to std::string. So two
deep copies ... for each string field. I was thinking about modifying
protobuf compiler to generate QT/C++ based message classes but found
that WireFormat classes also make use of std::string's, so it seems
that I must modify entire protobuf library :( if I want to take data
directly from QByteArray.
Maybe it would by wise to introduce some additional methods in future,
like:

// Additional methods
static void WriteString(field_number, const char *value, int size,
output);
static void WriteBytes (field_number, const char *value, int size,
output);

// Current methods
static void WriteString(field_number, const string& value, output);
static void WriteBytes (field_number, const string& value, output);

This would allow not to rely only on std string but also use any other
structures for storing string data. So protobuf library coud be more
versatile. What do you think? Maybe someone was solving same problems
as me?

Kenton Varda

unread,
Sep 14, 2010, 8:48:50 PM9/14/10
to Algirdasss, Protocol Buffers
The methods of WireFormat are just short helpers that call into CodedOutputStream.  CodedOutputStream has methods that accept a raw buffer pointer and size.  So you could get away with modifying the code generator only if you call the CodedOutputStream methods directly.

That said, what you're doing is pretty fragile regardless.  WireFormat is an internal interface that may change from release to release.  Unfortunately I don't think it's practical for us to allow users to use arbitrary string classes without an extra copy.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Reply all
Reply to author
Forward
0 new messages