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 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "mojo/public/libs/message/message.h" |
| 13 |
| 14 namespace mojo { |
| 15 |
| 16 class MessageBuilder { |
| 17 public: |
| 18 MessageBuilder(); |
| 19 ~MessageBuilder(); |
| 20 |
| 21 bool Initialize(uint32_t type); |
| 22 |
| 23 bool Append(uint16_t name, bool value); |
| 24 |
| 25 bool Append(uint16_t name, int8_t value); |
| 26 bool Append(uint16_t name, int16_t value); |
| 27 bool Append(uint16_t name, int32_t value); |
| 28 bool Append(uint16_t name, int64_t value); |
| 29 |
| 30 bool Append(uint16_t name, uint8_t value); |
| 31 bool Append(uint16_t name, uint16_t value); |
| 32 bool Append(uint16_t name, uint32_t value); |
| 33 bool Append(uint16_t name, uint64_t value); |
| 34 |
| 35 bool Append(uint16_t name, float value); |
| 36 bool Append(uint16_t name, double value); |
| 37 |
| 38 bool Append(uint16_t name, const std::string& value); |
| 39 bool Append(uint16_t name, const void* bytes, size_t num_bytes); |
| 40 |
| 41 template <typename C> |
| 42 bool Append(uint16_t name, const C& container) { |
| 43 return Append(name, container.data(), container.size()); |
| 44 } |
| 45 |
| 46 bool Append(uint16_t name, Handle handle); |
| 47 bool Append(uint16_t name, const Message& message); |
| 48 |
| 49 bool Finish(Message* message); |
| 50 |
| 51 private: |
| 52 bool AppendU32(uint16_t name, MessageFieldType field_type, uint32_t value); |
| 53 bool AppendU64(uint16_t name, MessageFieldType field_type, uint64_t value); |
| 54 bool AppendArray(uint16_t name, MessageFieldType field_type, |
| 55 const void* bytes, size_t num_bytes); |
| 56 |
| 57 bool AppendHeader(uint16_t name, MessageFieldType field_type); |
| 58 bool AppendPadding(size_t num_bytes); |
| 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_PUBLIC_LIBS_MESSAGE_BUILDER_H_ |
OLD | NEW |