OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 REMOTING_BASE_PROTOCOL_DECODER_H_ |
| 6 #define REMOTING_BASE_PROTOCOL_DECODER_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/ref_counted.h" |
| 12 #include "google/protobuf/message_lite.h" |
| 13 #include "media/base/data_buffer.h" |
| 14 #include "remoting/base/protocol/chromotocol.pb.h" |
| 15 |
| 16 namespace remoting { |
| 17 |
| 18 typedef std::vector<chromotocol_pb::HostMessage*> HostMessageList; |
| 19 typedef std::vector<chromotocol_pb::ClientMessage*> ClientMessageList; |
| 20 |
| 21 // A protocol decoder is used to decode data transmitted in the chromoting |
| 22 // network. |
| 23 // TODO(hclam): Defines the interface and implement methods. |
| 24 class ProtocolDecoder { |
| 25 public: |
| 26 ProtocolDecoder(); |
| 27 |
| 28 virtual ~ProtocolDecoder() {} |
| 29 |
| 30 // Parse data received from network into ClientMessages. Ownership of |data| |
| 31 // is passed to this object and output is written to |messages|. |
| 32 virtual void ParseClientMessages(scoped_refptr<media::DataBuffer> data, |
| 33 ClientMessageList* messages); |
| 34 |
| 35 // Parse data received from network into HostMessages. Ownership of |data| |
| 36 // is passed to this object and output is written to |messages|. |
| 37 virtual void ParseHostMessages(scoped_refptr<media::DataBuffer> data, |
| 38 HostMessageList* messages); |
| 39 |
| 40 private: |
| 41 // A private method used to parse data received from network into protocol |
| 42 // buffers. |
| 43 template <typename T> |
| 44 void ParseMessages(scoped_refptr<media::DataBuffer> data, |
| 45 std::vector<T*>* messages); |
| 46 |
| 47 // Parse one message from |data_list_|. Return true if sucessful. |
| 48 template <typename T> |
| 49 bool ParseOneMessage(T** messages); |
| 50 |
| 51 // A utility method to read payload size of the protocol buffer from the |
| 52 // data list. Return false if we don't have enough data. |
| 53 bool GetPayloadSize(int* size); |
| 54 |
| 55 typedef std::deque<scoped_refptr<media::DataBuffer> > DataList; |
| 56 DataList data_list_; |
| 57 int last_read_position_; |
| 58 |
| 59 // Count the number of bytes in |data_list_| not read. |
| 60 int available_bytes_; |
| 61 |
| 62 // Stores the size of the next payload if known. |
| 63 int next_payload_; |
| 64 |
| 65 // True if the size of the next payload is known. After one payload is read, |
| 66 // this is reset to false. |
| 67 bool next_payload_known_; |
| 68 }; |
| 69 |
| 70 } // namespace remoting |
| 71 |
| 72 #endif // REMOTING_BASE_PROTOCOL_DECODER_H_ |
OLD | NEW |