Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: lib/protobuf/runtime/PbReader.dart

Issue 10595002: Protocol Buffer runtime library and 'protoc' plugin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Work around http://code.google.com/p/dart/issues/detail?id=3806 Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/protobuf/runtime/PbList.dart ('k') | lib/protobuf/runtime/Protobuf.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * The PbReader reads bytes from some source, careful not to read more bytes
7 * than requested on destructive reads.
8 */
9 interface PbReader {
10 /**
11 * Returns whether more data may be available on this PbReader.
12 */
13 bool get closed();
14
15 /**
16 * Provides the position within the current PbReader.
17 */
18 int get position();
19
20 /**
21 * Reads a single byte and makes it available as a Future.
22 */
23 Future<int> readByte();
24
25 /**
26 * Reads the bytes requested and makes them available as a Future.
27 * Unspecified byte count instructs the method to read to the end.
28 */
29 Future<List<int>> readBytes([int count]);
30
31 /**
32 * Permits reads beyond current readBytes target for efficiency
33 */
34 void setReadAhead([int count]);
35 }
36
37 class PbBufferReader {
38 PbBufferReader(List<int> bytes) {
39 _buffer = new PbByteBuffer();
40 _buffer.add(bytes);
41 }
42
43 bool get closed() => _buffer.isEmpty;
44
45 int get position() => _position;
46
47 Future<int> readByte() {
48 int byte = _buffer.readByte();
49 if (byte != null) _position++;
50 return new Future.immediate(byte);
51 }
52
53 Future<List<int>> readBytes([int count = -1]) {
54 List<int> bytes = _buffer.readBytes(count);
55 if (bytes != null) _position += bytes.length;
56 return new Future.immediate(bytes);
57 }
58
59 void setReadAhead([int count = -1]) {}
60
61 PbByteBuffer _buffer;
62 int _position = 0;
63 }
OLDNEW
« no previous file with comments | « lib/protobuf/runtime/PbList.dart ('k') | lib/protobuf/runtime/Protobuf.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698