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

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: Added in the DEPS file as suggested Created 8 years, 10 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
Index: dbus/message.cc
diff --git a/dbus/message.cc b/dbus/message.cc
index 2750cb187a08329d1e196c6d54817d41180ee54b..501ed45e10049161b4754f7ed2195b4075f93a5b 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 {
@@ -592,6 +595,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);
}
@@ -799,6 +814,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);
}
« no previous file with comments | « dbus/message.h ('k') | dbus/message_unittest.cc » ('j') | dbus/test_proto.proto » ('J')

Powered by Google App Engine
This is Rietveld 408576698