Initialize all data members in HTTPResponseInfo's new ctor and remove the related...
[chromium-blink-merge.git] / remoting / base / protocol_decoder.h
blob119198fdff083dc845355f8af19e2c5ac299435f
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.
5 #ifndef REMOTING_BASE_PROTOCOL_DECODER_H_
6 #define REMOTING_BASE_PROTOCOL_DECODER_H_
8 #include <deque>
9 #include <vector>
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"
16 namespace remoting {
18 typedef std::vector<HostMessage*> HostMessageList;
19 typedef std::vector<ClientMessage*> ClientMessageList;
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();
28 virtual ~ProtocolDecoder() {}
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);
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);
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);
47 // Parse one message from |data_list_|. Return true if sucessful.
48 template <typename T>
49 bool ParseOneMessage(T** messages);
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);
55 typedef std::deque<scoped_refptr<media::DataBuffer> > DataList;
56 DataList data_list_;
57 size_t last_read_position_;
59 // Count the number of bytes in |data_list_| not read.
60 size_t available_bytes_;
62 // Stores the size of the next payload if known.
63 size_t next_payload_;
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_;
70 } // namespace remoting
72 #endif // REMOTING_BASE_PROTOCOL_DECODER_H_