OLD | NEW |
| (Empty) |
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_LIBS_MESSAGE_MESSAGE_BUIDER_H_ | |
6 #define MOJO_PUBLIC_LIBS_MESSAGE_MESSAGE_BUIDER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "mojo/public/libs/message/message.h" | |
14 | |
15 namespace mojo { | |
16 | |
17 class MessageBuilder { | |
18 public: | |
19 MessageBuilder(); | |
20 ~MessageBuilder(); | |
21 | |
22 bool Initialize(uint32_t message_name); | |
23 | |
24 bool Append(uint16_t name, bool value); | |
25 | |
26 bool Append(uint16_t name, int8_t value); | |
27 bool Append(uint16_t name, int16_t value); | |
28 bool Append(uint16_t name, int32_t value); | |
29 bool Append(uint16_t name, int64_t value); | |
30 | |
31 bool Append(uint16_t name, uint8_t value); | |
32 bool Append(uint16_t name, uint16_t value); | |
33 bool Append(uint16_t name, uint32_t value); | |
34 bool Append(uint16_t name, uint64_t value); | |
35 | |
36 bool Append(uint16_t name, float value); | |
37 bool Append(uint16_t name, double value); | |
38 | |
39 bool Append(uint16_t name, const std::string& value); | |
40 bool Append(uint16_t name, const void* bytes, size_t num_bytes); | |
41 | |
42 template <typename C> | |
43 bool Append(uint16_t name, const C& container) { | |
44 return Append(name, container.data(), container.size()); | |
45 } | |
46 | |
47 // TODO(darin): Add support for arrays of other types. | |
48 | |
49 bool Append(uint16_t name, Handle handle); | |
50 bool Append(uint16_t name, const Message& message); | |
51 | |
52 bool Finish(Message* message); | |
53 | |
54 private: | |
55 bool AppendU32(uint16_t name, MessageFieldType field_type, uint32_t value); | |
56 bool AppendU64(uint16_t name, MessageFieldType field_type, uint64_t value); | |
57 bool AppendArray(uint16_t name, MessageFieldType field_type, | |
58 const void* bytes, size_t num_bytes); | |
59 | |
60 bool AppendHeader(uint16_t name, MessageFieldType field_type); | |
61 bool AppendPadding(size_t num_bytes); | |
62 bool AppendRawBytes(const void* bytes, size_t num_bytes); | |
63 | |
64 std::vector<uint8_t> data_; | |
65 std::vector<Handle> handles_; | |
66 }; | |
67 | |
68 } // namespace mojo | |
69 | |
70 #endif // MOJO_PUBLIC_LIBS_MESSAGE_BUILDER_H_ | |
OLD | NEW |