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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/protobuf/runtime/PbList.dart ('k') | lib/protobuf/runtime/Protobuf.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/protobuf/runtime/PbReader.dart
diff --git a/lib/protobuf/runtime/PbReader.dart b/lib/protobuf/runtime/PbReader.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2a7ca04a5139ffbcf78a6934b948e08355016860
--- /dev/null
+++ b/lib/protobuf/runtime/PbReader.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/**
+ * The PbReader reads bytes from some source, careful not to read more bytes
+ * than requested on destructive reads.
+ */
+interface PbReader {
+ /**
+ * Returns whether more data may be available on this PbReader.
+ */
+ bool get closed();
+
+ /**
+ * Provides the position within the current PbReader.
+ */
+ int get position();
+
+ /**
+ * Reads a single byte and makes it available as a Future.
+ */
+ Future<int> readByte();
+
+ /**
+ * Reads the bytes requested and makes them available as a Future.
+ * Unspecified byte count instructs the method to read to the end.
+ */
+ Future<List<int>> readBytes([int count]);
+
+ /**
+ * Permits reads beyond current readBytes target for efficiency
+ */
+ void setReadAhead([int count]);
+}
+
+class PbBufferReader {
+ PbBufferReader(List<int> bytes) {
+ _buffer = new PbByteBuffer();
+ _buffer.add(bytes);
+ }
+
+ bool get closed() => _buffer.isEmpty;
+
+ int get position() => _position;
+
+ Future<int> readByte() {
+ int byte = _buffer.readByte();
+ if (byte != null) _position++;
+ return new Future.immediate(byte);
+ }
+
+ Future<List<int>> readBytes([int count = -1]) {
+ List<int> bytes = _buffer.readBytes(count);
+ if (bytes != null) _position += bytes.length;
+ return new Future.immediate(bytes);
+ }
+
+ void setReadAhead([int count = -1]) {}
+
+ PbByteBuffer _buffer;
+ int _position = 0;
+}
« 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