• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_BUILDER_H_
6 #define MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_BUILDER_H_
7 
8 #include <stdint.h>
9 
10 #include "mojo/public/bindings/lib/buffer.h"
11 
12 namespace mojo {
13 struct MessageData;
14 
15 namespace internal {
16 
17 // Used to construct a MessageData object.
18 class MessageBuilder {
19  public:
20   MessageBuilder(uint32_t message_name, size_t payload_size);
21   ~MessageBuilder();
22 
buffer()23   Buffer* buffer() { return &buf_; }
24 
25   // Call Finish when done making allocations in |buffer()|. A heap-allocated
26   // MessageData object will be returned. When no longer needed, use |free()|
27   // to release the MessageData object's memory.
28   MessageData* Finish();
29 
30  private:
31   FixedBuffer buf_;
32 
33   MOJO_DISALLOW_COPY_AND_ASSIGN(MessageBuilder);
34 };
35 
36 }  // namespace internal
37 }  // namespace mojo
38 
39 #endif  // MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_BUILDER_H_
40