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

Unified Diff: mojo/public/libs/message/message_builder.h

Issue 23629032: mojo: MessageBuilder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compilation error. Created 7 years, 3 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
« no previous file with comments | « mojo/public/libs/message/message.cc ('k') | mojo/public/libs/message/message_builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/libs/message/message_builder.h
diff --git a/mojo/public/libs/message/message_builder.h b/mojo/public/libs/message/message_builder.h
new file mode 100644
index 0000000000000000000000000000000000000000..671499b747a59b49dd07a971778b331e370c15ba
--- /dev/null
+++ b/mojo/public/libs/message/message_builder.h
@@ -0,0 +1,70 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_LIBS_MESSAGE_MESSAGE_BUIDER_H_
+#define MOJO_PUBLIC_LIBS_MESSAGE_MESSAGE_BUIDER_H_
+
+#include <stdint.h>
+
+#include <string>
+#include <vector>
+
+#include "mojo/public/libs/message/message.h"
+
+namespace mojo {
+
+class MessageBuilder {
+ public:
+ MessageBuilder();
+ ~MessageBuilder();
+
+ bool Initialize(uint32_t message_name);
+
+ bool Append(uint16_t name, bool value);
+
+ bool Append(uint16_t name, int8_t value);
+ bool Append(uint16_t name, int16_t value);
+ bool Append(uint16_t name, int32_t value);
+ bool Append(uint16_t name, int64_t value);
+
+ bool Append(uint16_t name, uint8_t value);
+ bool Append(uint16_t name, uint16_t value);
+ bool Append(uint16_t name, uint32_t value);
+ bool Append(uint16_t name, uint64_t value);
+
+ bool Append(uint16_t name, float value);
+ bool Append(uint16_t name, double value);
+
+ bool Append(uint16_t name, const std::string& value);
+ bool Append(uint16_t name, const void* bytes, size_t num_bytes);
+
+ template <typename C>
+ bool Append(uint16_t name, const C& container) {
+ return Append(name, container.data(), container.size());
+ }
+
+ // TODO(darin): Add support for arrays of other types.
+
+ bool Append(uint16_t name, Handle handle);
+ bool Append(uint16_t name, const Message& message);
+
+ bool Finish(Message* message);
+
+ private:
+ bool AppendU32(uint16_t name, MessageFieldType field_type, uint32_t value);
+ bool AppendU64(uint16_t name, MessageFieldType field_type, uint64_t value);
+ bool AppendArray(uint16_t name, MessageFieldType field_type,
+ const void* bytes, size_t num_bytes);
+
+ bool AppendHeader(uint16_t name, MessageFieldType field_type);
+ bool AppendPadding(size_t num_bytes);
+ bool AppendRawBytes(const void* bytes, size_t num_bytes);
+
+ std::vector<uint8_t> data_;
+ std::vector<Handle> handles_;
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_LIBS_MESSAGE_BUILDER_H_
« no previous file with comments | « mojo/public/libs/message/message.cc ('k') | mojo/public/libs/message/message_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698