OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Streams classes. | 5 // Streams classes. |
6 // | 6 // |
7 // These memory-resident streams are used for serializing data into a sequential | 7 // These memory-resident streams are used for serializing data into a sequential |
8 // region of memory. | 8 // region of memory. |
9 // Streams are divided into SourceStreams for reading and SinkStreams for | 9 // Streams are divided into SourceStreams for reading and SinkStreams for |
10 // writing. Streams are aggregated into Sets which allows several streams to be | 10 // writing. Streams are aggregated into Sets which allows several streams to be |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 | 27 |
28 namespace courgette { | 28 namespace courgette { |
29 | 29 |
30 class SourceStream; | 30 class SourceStream; |
31 class SinkStream; | 31 class SinkStream; |
32 | 32 |
33 // Maximum number of streams in a stream set. | 33 // Maximum number of streams in a stream set. |
34 static const unsigned int kMaxStreams = 10; | 34 static const unsigned int kMaxStreams = 10; |
35 | 35 |
| 36 // A simple interface for reading binary data. |
| 37 class BasicBuffer { |
| 38 public: |
| 39 BasicBuffer() {} |
| 40 virtual ~BasicBuffer() {} |
| 41 virtual const uint8_t* data() const = 0; |
| 42 virtual size_t length() const = 0; |
| 43 }; |
| 44 |
36 // A SourceStream allows a region of memory to be scanned by a sequence of Read | 45 // A SourceStream allows a region of memory to be scanned by a sequence of Read |
37 // operations. The stream does not own the memory. | 46 // operations. The stream does not own the memory. |
38 class SourceStream { | 47 class SourceStream { |
39 public: | 48 public: |
40 SourceStream() : start_(NULL), end_(NULL), current_(NULL) {} | 49 SourceStream() : start_(NULL), end_(NULL), current_(NULL) {} |
41 | 50 |
42 // Initializes the SourceStream to yield the bytes at |pointer|. The caller | 51 // Initializes the SourceStream to yield the bytes at |pointer|. The caller |
43 // still owns the memory at |pointer| and should free the memory only after | 52 // still owns the memory at |pointer| and should free the memory only after |
44 // the last use of the stream. | 53 // the last use of the stream. |
45 void Init(const void* pointer, size_t length) { | 54 void Init(const void* pointer, size_t length) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 236 |
228 private: | 237 private: |
229 CheckBool CopyHeaderTo(SinkStream* stream) WARN_UNUSED_RESULT; | 238 CheckBool CopyHeaderTo(SinkStream* stream) WARN_UNUSED_RESULT; |
230 | 239 |
231 size_t count_; | 240 size_t count_; |
232 SinkStream streams_[kMaxStreams]; | 241 SinkStream streams_[kMaxStreams]; |
233 | 242 |
234 DISALLOW_COPY_AND_ASSIGN(SinkStreamSet); | 243 DISALLOW_COPY_AND_ASSIGN(SinkStreamSet); |
235 }; | 244 }; |
236 | 245 |
237 } // namespace | 246 } // namespace courgette |
| 247 |
238 #endif // COURGETTE_STREAMS_H_ | 248 #endif // COURGETTE_STREAMS_H_ |
OLD | NEW |