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

Unified Diff: mojo/public/cpp/bindings/lib/message_builder.h

Issue 1460463003: Move mojo::internal::MessageBuilder out of the |internal| namespace. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: formatting + style changes (from trung comments) Created 5 years, 1 month 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 | « no previous file | mojo/public/cpp/bindings/lib/message_builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/message_builder.h
diff --git a/mojo/public/cpp/bindings/lib/message_builder.h b/mojo/public/cpp/bindings/lib/message_builder.h
index 86ae71db142431980d02dfef94759742dd1abaf4..3587dba6f9cb21a9b49ff4952b7ae2c2f7f89906 100644
--- a/mojo/public/cpp/bindings/lib/message_builder.h
+++ b/mojo/public/cpp/bindings/lib/message_builder.h
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// These are helper classes for allocating, aligning, and framing a
+// |mojo::Message|. They are mainly used from within the generated C++ bindings.
+
#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
#define MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
@@ -12,28 +15,39 @@
#include "mojo/public/cpp/bindings/message.h"
namespace mojo {
-class Message;
-namespace internal {
+class Message;
+// MessageBuilder helps initialize and frame a |mojo::Message| that does not
+// expect a response message, and therefore does not tag the message with a
+// request id (which may save some bytes).
+//
+// The underlying |Message| is owned by MessageBuilder, but can be permanently
+// moved by accessing |message()| and calling its |MoveTo()|.
class MessageBuilder {
public:
+ // This frames and configures a |mojo::Message| with the given message name.
MessageBuilder(uint32_t name, size_t payload_size);
~MessageBuilder();
- Buffer* buffer() { return &buf_; }
Message* message() { return &message_; }
+ // TODO(vardhan): |buffer()| is internal and only consumed by internal classes
+ // and unittests. Consider making it private + friend class its consumers?
+ internal::Buffer* buffer() { return &buf_; }
+
protected:
MessageBuilder();
void Initialize(size_t size);
Message message_;
- FixedBuffer buf_;
+ internal::FixedBuffer buf_;
MOJO_DISALLOW_COPY_AND_ASSIGN(MessageBuilder);
};
+namespace internal {
+
class MessageWithRequestIDBuilder : public MessageBuilder {
public:
MessageWithRequestIDBuilder(uint32_t name,
@@ -42,27 +56,37 @@ class MessageWithRequestIDBuilder : public MessageBuilder {
uint64_t request_id);
};
-class RequestMessageBuilder : public MessageWithRequestIDBuilder {
+} // namespace internal
+
+// Builds a |mojo::Message| that is a "request" message that expects a response
+// message. You can give it a unique |request_id| (with which you can construct
+// a response message) by calling |message()->set_request_id()|.
+//
+// Has the same interface as |mojo::MessageBuilder|.
+class RequestMessageBuilder : public internal::MessageWithRequestIDBuilder {
public:
RequestMessageBuilder(uint32_t name, size_t payload_size)
: MessageWithRequestIDBuilder(name,
payload_size,
- kMessageExpectsResponse,
+ internal::kMessageExpectsResponse,
0) {}
};
-class ResponseMessageBuilder : public MessageWithRequestIDBuilder {
+// Builds a |mojo::Message| that is a "response" message which pertains to a
+// |request_id|.
+//
+// Has the same interface as |mojo::MessageBuilder|.
+class ResponseMessageBuilder : public internal::MessageWithRequestIDBuilder {
public:
ResponseMessageBuilder(uint32_t name,
size_t payload_size,
uint64_t request_id)
: MessageWithRequestIDBuilder(name,
payload_size,
- kMessageIsResponse,
+ internal::kMessageIsResponse,
request_id) {}
};
-} // namespace internal
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/message_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698