summaryrefslogtreecommitdiffstats
path: root/dbus/message.cc
diff options
context:
space:
mode:
authorrharrison@chromium.org <rharrison@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-09 18:14:08 +0000
committerrharrison@chromium.org <rharrison@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-09 18:14:08 +0000
commitc033c5087d504ce089ec51763292b11bc1c6850d (patch)
tree8016ffc595f4106afd4c9c950e920d88f7a6d0cf /dbus/message.cc
parentb23c3bce93b8749c5b8c9b37e8859f4dd66e7b36 (diff)
downloadchromium_src-c033c5087d504ce089ec51763292b11bc1c6850d.zip
chromium_src-c033c5087d504ce089ec51763292b11bc1c6850d.tar.gz
chromium_src-c033c5087d504ce089ec51763292b11bc1c6850d.tar.bz2
Adding support for sending/receiving proto bufs to dbus library.
This CL add in support to dbus wrapping classes to send and receive protocol buffers. They take in a generic MessageLite, which all protocol buffers inherit from. It will then serialize the buffer and send it out as an array of bytes. On receiving the array of bytes will be parsed back into a protocol buffer. The operations for doing this are very canned and these methods are designed to allow devs to skip writing boilerplate. The methods are just wrappers around the appopriate byte array methods. BUG=chromium:112127 TEST=Ran new unittests Review URL: http://codereview.chromium.org/9315006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121248 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/message.cc')
-rw-r--r--dbus/message.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/dbus/message.cc b/dbus/message.cc
index bf2c2c3..db8184e 100644
--- a/dbus/message.cc
+++ b/dbus/message.cc
@@ -4,10 +4,13 @@
#include "dbus/message.h"
+#include <string>
+
#include "base/basictypes.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/stringprintf.h"
+#include "third_party/protobuf/src/google/protobuf/message_lite.h"
namespace {
@@ -593,6 +596,18 @@ void MessageWriter::AppendArrayOfObjectPaths(
CloseContainer(&array_writer);
}
+bool MessageWriter::AppendProtoAsArrayOfBytes(
+ 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);
}
@@ -801,6 +816,22 @@ bool MessageReader::PopArrayOfObjectPaths(
return true;
}
+bool MessageReader::PopArrayOfBytesAsProto(
+ google::protobuf::MessageLite* protobuf) {
+ DCHECK(protobuf != NULL);
+ char* serialized_buf = NULL;
+ size_t buf_size = 0;
+ 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);
}