Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 REMOTING_PROTOCOL_MESSAGE_DECODER_H_ | 5 #ifndef REMOTING_PROTOCOL_MESSAGE_DECODER_H_ |
| 6 #define REMOTING_PROTOCOL_MESSAGE_DECODER_H_ | 6 #define REMOTING_PROTOCOL_MESSAGE_DECODER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 // | message_size | message_data | | 28 // | message_size | message_data | |
| 29 // +--------------+--------------+ | 29 // +--------------+--------------+ |
| 30 // | 30 // |
| 31 // Here, message_size is 4-byte integer that represents size of | 31 // Here, message_size is 4-byte integer that represents size of |
| 32 // message_data in bytes. message_data - content of the message. | 32 // message_data in bytes. message_data - content of the message. |
| 33 class MessageDecoder { | 33 class MessageDecoder { |
| 34 public: | 34 public: |
| 35 MessageDecoder(); | 35 MessageDecoder(); |
| 36 virtual ~MessageDecoder(); | 36 virtual ~MessageDecoder(); |
| 37 | 37 |
| 38 bool is_buffer_empty() { return buffer_.total_bytes() == 0; } | |
|
Wez
2015/01/21 01:35:40
Needs a comment to clarify the difference between
Sergey Ulanov
2015/01/29 01:33:29
Done.
| |
| 39 | |
| 38 // Add next chunk of data. MessageDecoder retains |data| until all | 40 // Add next chunk of data. MessageDecoder retains |data| until all |
| 39 // its bytes are consumed. | 41 // its bytes are consumed. |
| 40 void AddData(scoped_refptr<net::IOBuffer> data, int data_size); | 42 void AddData(scoped_refptr<net::IOBuffer> data, int data_size); |
| 41 | 43 |
| 42 // Returns next message from the stream. Ownership of the result is | 44 // Returns next message from the stream. Ownership of the result is |
| 43 // passed to the caller. Returns nullptr if there are no complete | 45 // passed to the caller. Returns nullptr if there are no complete |
| 44 // messages yet, otherwise returns a buffer that contains one | 46 // messages yet, otherwise returns a buffer that contains one |
| 45 // message. | 47 // message. |
| 46 CompoundBuffer* GetNextMessage(); | 48 CompoundBuffer* GetNextMessage(); |
| 47 | 49 |
| 48 private: | 50 private: |
| 49 // Retrieves the read payload size of the current protocol buffer via |size|. | 51 // Retrieves the read payload size of the current protocol buffer via |size|. |
| 50 // Returns false and leaves |size| unmodified, if we do not have enough data | 52 // Returns false and leaves |size| unmodified, if we do not have enough data |
| 51 // to retrieve the current size. | 53 // to retrieve the current size. |
| 52 bool GetPayloadSize(int* size); | 54 bool GetPayloadSize(int* size); |
| 53 | 55 |
| 54 CompoundBuffer buffer_; | 56 CompoundBuffer buffer_; |
| 55 | 57 |
| 56 // |next_payload_| stores the size of the next payload if known. | 58 // |next_payload_| stores the size of the next payload if known. |
| 57 // |next_payload_known_| is true if the size of the next payload is known. | 59 // |next_payload_known_| is true if the size of the next payload is known. |
| 58 // After one payload is read this is reset to false. | 60 // After one payload is read this is reset to false. |
| 59 int next_payload_; | 61 int next_payload_; |
| 60 bool next_payload_known_; | 62 bool next_payload_known_; |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 } // namespace protocol | 65 } // namespace protocol |
| 64 } // namespace remoting | 66 } // namespace remoting |
| 65 | 67 |
| 66 #endif // REMOTING_PROTOCOL_MESSAGE_DECODER_H_ | 68 #endif // REMOTING_PROTOCOL_MESSAGE_DECODER_H_ |
| OLD | NEW |