OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ |
7 | 7 |
8 #include <assert.h> | 8 #include <assert.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 request_id = request_id; | 56 request_id = request_id; |
57 } | 57 } |
58 | 58 |
59 // Access the payload. | 59 // Access the payload. |
60 const uint8_t* payload() const { | 60 const uint8_t* payload() const { |
61 return reinterpret_cast<const uint8_t*>(data_) + data_->header.num_bytes; | 61 return reinterpret_cast<const uint8_t*>(data_) + data_->header.num_bytes; |
62 } | 62 } |
63 uint8_t* mutable_payload() { | 63 uint8_t* mutable_payload() { |
64 return reinterpret_cast<uint8_t*>(data_) + data_->header.num_bytes; | 64 return reinterpret_cast<uint8_t*>(data_) + data_->header.num_bytes; |
65 } | 65 } |
| 66 uint32_t payload_num_bytes() const { |
| 67 assert(data_num_bytes_ >= data_->header.num_bytes); |
| 68 return data_num_bytes_ - data_->header.num_bytes; |
| 69 } |
66 | 70 |
67 // Access the handles. | 71 // Access the handles. |
68 const std::vector<Handle>* handles() const { return &handles_; } | 72 const std::vector<Handle>* handles() const { return &handles_; } |
69 std::vector<Handle>* mutable_handles() { return &handles_; } | 73 std::vector<Handle>* mutable_handles() { return &handles_; } |
70 | 74 |
71 private: | 75 private: |
72 uint32_t data_num_bytes_; | 76 uint32_t data_num_bytes_; |
73 internal::MessageData* data_; // Heap-allocated using malloc. | 77 internal::MessageData* data_; // Heap-allocated using malloc. |
74 std::vector<Handle> handles_; | 78 std::vector<Handle> handles_; |
75 | 79 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // otherwise returns an error code if something went wrong. | 114 // otherwise returns an error code if something went wrong. |
111 // | 115 // |
112 // NOTE: The message hasn't been validated and may be malformed! | 116 // NOTE: The message hasn't been validated and may be malformed! |
113 MojoResult ReadAndDispatchMessage(MessagePipeHandle handle, | 117 MojoResult ReadAndDispatchMessage(MessagePipeHandle handle, |
114 MessageReceiver* receiver, | 118 MessageReceiver* receiver, |
115 bool* receiver_result); | 119 bool* receiver_result); |
116 | 120 |
117 } // namespace mojo | 121 } // namespace mojo |
118 | 122 |
119 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ | 123 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ |
OLD | NEW |