OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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_IPC_MESSAGE_IPC_MESSAGE_BUIDER_H_ |
| 6 #define MOJO_IPC_MESSAGE_IPC_MESSAGE_BUIDER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "mojo/ipc/core/ipc_handle.h" |
| 13 #include "mojo/ipc/message/ipc_message.h" |
| 14 |
| 15 namespace mojo { |
| 16 |
| 17 class IPCMessageBuilder { |
| 18 public: |
| 19 IPCMessageBuilder(); |
| 20 ~IPCMessageBuilder(); |
| 21 |
| 22 bool Initialize(uint32_t type); |
| 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 bool Append(uint16_t name, Handle handle); |
| 48 bool Append(uint16_t name, const IPCMessage& message); |
| 49 |
| 50 bool Finish(IPCMessage* message); |
| 51 |
| 52 private: |
| 53 bool AppendU32(uint16_t name, IPCMessageFieldType field_type, uint32_t value); |
| 54 bool AppendU64(uint16_t name, IPCMessageFieldType field_type, uint64_t value); |
| 55 bool AppendVariableLength(uint16_t name, IPCMessageFieldType field_type, |
| 56 const void* bytes, size_t num_bytes); |
| 57 |
| 58 bool AppendHeader(uint16_t name, IPCMessageFieldType field_type); |
| 59 bool AppendRawBytes(const void* bytes, size_t num_bytes); |
| 60 |
| 61 std::vector<uint8_t> data_; |
| 62 std::vector<Handle> handles_; |
| 63 }; |
| 64 |
| 65 } // namespace mojo |
| 66 |
| 67 #endif // MOJO_IPC_IPC_MESSAGE_BUILDER_H_ |
OLD | NEW |