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_
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"
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
23 // TODO(hclam): Defines the interface and implement methods.
24 class 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
);
41 // A private method used to parse data received from network into protocol
44 void ParseMessages(scoped_refptr
<media::DataBuffer
> data
,
45 std::vector
<T
*>* messages
);
47 // Parse one message from |data_list_|. Return true if sucessful.
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
;
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.
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_