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 // MultipleArrayInputStream implements ZeroCopyInputStream to be used by | |
6 // protobuf to decode bytes into a protocol buffer message. | |
7 // | |
8 // This input stream is made of multiple IOBuffers received from the network. | |
9 // This object retains the IOBuffers added to it. | |
10 // | |
11 // Internally, we wrap each added IOBuffer in a DrainableIOBuffer. This allows | |
12 // us to track how much data has been consumed from each IOBuffer. | |
13 | |
14 #ifndef REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_ | |
15 #define REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_ | |
16 | |
17 #include <vector> | |
18 | |
19 #include "base/basictypes.h" | |
20 #include "base/ref_counted.h" | |
21 #include "google/protobuf/io/zero_copy_stream.h" | |
22 | |
23 namespace net { | |
24 class DrainableIOBuffer; | |
25 class IOBuffer; | |
26 } // namespace net | |
27 | |
28 namespace remoting { | |
29 | |
30 class MultipleArrayInputStream : | |
31 public google::protobuf::io::ZeroCopyInputStream { | |
32 public: | |
33 MultipleArrayInputStream(); | |
34 virtual ~MultipleArrayInputStream(); | |
35 | |
36 // Add a buffer to the list. |buffer| is retained by this object. | |
37 void AddBuffer(net::IOBuffer* buffer, int size); | |
38 | |
39 // google::protobuf::io::ZeroCopyInputStream interface. | |
40 virtual bool Next(const void** data, int* size); | |
41 virtual void BackUp(int count); | |
42 virtual bool Skip(int count); | |
43 virtual int64 ByteCount() const; | |
44 | |
45 private: | |
46 std::vector<scoped_refptr<net::DrainableIOBuffer> > buffers_; | |
47 | |
48 size_t current_buffer_; | |
49 int position_; | |
50 int last_returned_size_; | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(MultipleArrayInputStream); | |
53 }; | |
54 | |
55 } // namespace remoting | |
56 | |
57 #endif // REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_ | |
OLD | NEW |