Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1918)

Unified Diff: dbus/message.cc

Issue 9315006: Adding support for sending/receiving proto bufs to dbus library. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Made changes requested by satorux Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« dbus/message.h ('K') | « dbus/message.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/message.cc
diff --git a/dbus/message.cc b/dbus/message.cc
index 2750cb187a08329d1e196c6d54817d41180ee54b..a6f8178442366c690e1b5332adea9bca3eda9f25 100644
--- a/dbus/message.cc
+++ b/dbus/message.cc
@@ -4,6 +4,8 @@
#include "dbus/message.h"
+#include <string>
+
#include "base/basictypes.h"
#include "base/format_macros.h"
#include "base/logging.h"
@@ -592,6 +594,18 @@ void MessageWriter::AppendArrayOfObjectPaths(
CloseContainer(&array_writer);
}
+bool MessageWriter::AppendProtocolBuffer(
+ const google::protobuf::MessageLite& protobuf) {
+ std::string serialized_proto;
+ if (!protobuf.SerializeToString(&serialized_proto)) {
+ LOG(ERROR) << "Unable to serialize supplied protocol buffer";
+ return false;
+ }
+ AppendArrayOfBytes(reinterpret_cast<const uint8*>(serialized_proto.data()),
+ serialized_proto.size());
+ return true;
+}
+
void MessageWriter::AppendVariantOfByte(uint8 value) {
AppendVariantOfBasic(DBUS_TYPE_BYTE, &value);
}
@@ -799,6 +813,21 @@ bool MessageReader::PopArrayOfObjectPaths(
return true;
}
+bool MessageReader::PopProtocolBuffer(google::protobuf::MessageLite* protobuf) {
+ DCHECK(protobuf != NULL);
+ char* serialized_buf;
+ size_t buf_size;
satorux1 2012/01/31 21:42:31 Please initialize them. char* serialized_buf = NU
rharrison 2012/02/01 19:03:20 Done.
+ if (!PopArrayOfBytes(reinterpret_cast<uint8**>(&serialized_buf), &buf_size)) {
+ LOG(ERROR) << "Error reading array of bytes";
+ return false;
+ }
+ if (!protobuf->ParseFromArray(serialized_buf, buf_size)) {
+ LOG(ERROR) << "Failed to parse protocol buffer from array";
+ return false;
+ }
+ return true;
+}
+
bool MessageReader::PopVariantOfByte(uint8* value) {
return PopVariantOfBasic(DBUS_TYPE_BYTE, value);
}
« dbus/message.h ('K') | « dbus/message.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698