| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_EDK_SYSTEM_PORTS_MESSAGE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_ |
| 6 #define MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_ | 6 #define MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "mojo/edk/system/ports/name.h" | 11 #include "mojo/edk/system/ports/name.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace edk { | 14 namespace edk { |
| 15 namespace ports { | 15 namespace ports { |
| 16 | 16 |
| 17 // A message consists of a header (array of bytes), payload (array of bytes) | 17 // A message consists of a header (array of bytes), payload (array of bytes) |
| 18 // and an array of ports. The header is used by the Node implementation. | 18 // and an array of ports. The header is used by the Node implementation. |
| 19 // | 19 // |
| 20 // This class is designed to be subclassed, and the subclass is responsible for | 20 // This class is designed to be subclassed, and the subclass is responsible for |
| 21 // providing the underlying storage. The header size will be aligned, and it | 21 // providing the underlying storage. The header size will be aligned, and it |
| 22 // should be followed in memory by the array of ports and finally the payload. | 22 // should be followed in memory by the array of ports and finally the payload. |
| 23 // | 23 // |
| 24 // NOTE: This class does not manage the lifetime of the ports it references. | 24 // NOTE: This class does not manage the lifetime of the ports it references. |
| 25 class Message { | 25 class Message { |
| 26 public: | 26 public: |
| 27 virtual ~Message() {} | 27 virtual ~Message() {} |
| 28 | 28 |
| 29 // Inspect the message at |bytes| and return the size of each section. | 29 // Inspect the message at |bytes| and return the size of each section. Returns |
| 30 static void Parse(const void* bytes, | 30 // |false| if the message is malformed and |true| otherwise. |
| 31 static bool Parse(const void* bytes, |
| 31 size_t num_bytes, | 32 size_t num_bytes, |
| 32 size_t* num_header_bytes, | 33 size_t* num_header_bytes, |
| 33 size_t* num_payload_bytes, | 34 size_t* num_payload_bytes, |
| 34 size_t* num_ports_bytes); | 35 size_t* num_ports_bytes); |
| 35 | 36 |
| 36 void* mutable_header_bytes() { return start_; } | 37 void* mutable_header_bytes() { return start_; } |
| 37 const void* header_bytes() const { return start_; } | 38 const void* header_bytes() const { return start_; } |
| 38 size_t num_header_bytes() const { return num_header_bytes_; } | 39 size_t num_header_bytes() const { return num_header_bytes_; } |
| 39 | 40 |
| 40 void* mutable_payload_bytes() { | 41 void* mutable_payload_bytes() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 size_t num_payload_bytes_ = 0; | 83 size_t num_payload_bytes_ = 0; |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 using ScopedMessage = scoped_ptr<Message>; | 86 using ScopedMessage = scoped_ptr<Message>; |
| 86 | 87 |
| 87 } // namespace ports | 88 } // namespace ports |
| 88 } // namespace edk | 89 } // namespace edk |
| 89 } // namespace mojo | 90 } // namespace mojo |
| 90 | 91 |
| 91 #endif // MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_ | 92 #endif // MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_ |
| OLD | NEW |