| 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 COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H | 6 #define COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 | 12 |
| 13 namespace proximity_auth { | 13 namespace proximity_auth { |
| 14 | 14 |
| 15 class WireMessage { | 15 class WireMessage { |
| 16 public: | 16 public: |
| 17 virtual ~WireMessage(); | 17 virtual ~WireMessage(); |
| 18 | 18 |
| 19 // Returns |true| iff the size of |message_bytes| is at least equal to the | 19 // Returns the deserialized message from |serialized_message|, or NULL if the |
| 20 // message length encoded in the message header. Returns false if the message | 20 // message is malformed. Sets |is_incomplete_message| to true if the message |
| 21 // header is not available. | 21 // does not have enough data to parse the header, or if the message length |
| 22 static bool IsCompleteMessage(const std::string& message_bytes); | 22 // encoded in the message header exceeds the size of the |serialized_message|. |
| 23 static scoped_ptr<WireMessage> Deserialize( |
| 24 const std::string& serialized_message, |
| 25 bool* is_incomplete_message); |
| 23 | 26 |
| 24 // Returns the deserialized message from |serialized_message|, or NULL if the | 27 const std::string& permit_id() const { return permit_id_; } |
| 25 // message is malformed. | 28 const std::string& payload() const { return payload_; } |
| 26 static scoped_ptr<WireMessage> Deserialize( | |
| 27 const std::string& serialized_message); | |
| 28 | 29 |
| 29 protected: | 30 protected: |
| 30 // Visible for tests. | 31 // Visible for tests. |
| 31 WireMessage(); | 32 WireMessage(const std::string& permit_id, const std::string& payload); |
| 32 | 33 |
| 33 private: | 34 private: |
| 35 // Identifier of the permit being used. |
| 36 // TODO(isherman): Describe in a bit more detail. |
| 37 const std::string permit_id_; |
| 38 |
| 39 // The message payload. |
| 40 const std::string payload_; |
| 41 |
| 34 DISALLOW_COPY_AND_ASSIGN(WireMessage); | 42 DISALLOW_COPY_AND_ASSIGN(WireMessage); |
| 35 }; | 43 }; |
| 36 | 44 |
| 37 } // namespace proximity_auth | 45 } // namespace proximity_auth |
| 38 | 46 |
| 39 #endif // COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H | 47 #endif // COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H |
| OLD | NEW |