Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / public / cpp / bindings / lib / message_builder.h
blobb4988ff9cb96f8d39143ceb01bd51ad05102f2e1
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
8 #include <stdint.h>
10 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
11 #include "mojo/public/cpp/bindings/lib/message_internal.h"
13 namespace mojo {
14 class Message;
16 namespace internal {
18 class MessageBuilder {
19 public:
20 MessageBuilder(uint32_t name, size_t payload_size);
21 ~MessageBuilder();
23 Buffer* buffer() { return &buf_; }
25 // Call Finish when done making allocations in |buffer()|. Upon return,
26 // |message| will contain the message data, and |buffer()| will no longer be
27 // valid to reference.
28 void Finish(Message* message);
30 protected:
31 explicit MessageBuilder(size_t size);
32 FixedBuffer buf_;
34 MOJO_DISALLOW_COPY_AND_ASSIGN(MessageBuilder);
37 class MessageWithRequestIDBuilder : public MessageBuilder {
38 public:
39 MessageWithRequestIDBuilder(uint32_t name, size_t payload_size,
40 uint32_t flags, uint64_t request_id);
43 class RequestMessageBuilder : public MessageWithRequestIDBuilder {
44 public:
45 RequestMessageBuilder(uint32_t name, size_t payload_size)
46 : MessageWithRequestIDBuilder(name, payload_size, kMessageExpectsResponse,
47 0) {
51 class ResponseMessageBuilder : public MessageWithRequestIDBuilder {
52 public:
53 ResponseMessageBuilder(uint32_t name, size_t payload_size,
54 uint64_t request_id)
55 : MessageWithRequestIDBuilder(name, payload_size, kMessageIsResponse,
56 request_id) {
60 } // namespace internal
61 } // namespace mojo
63 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_