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

Unified Diff: lib/protobuf/runtime/CodedReader.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/CodedBufferWriter.dart ('k') | lib/protobuf/runtime/CodedStreamReader.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/protobuf/runtime/CodedReader.dart
diff --git a/lib/protobuf/runtime/CodedReader.dart b/lib/protobuf/runtime/CodedReader.dart
new file mode 100644
index 0000000000000000000000000000000000000000..183d665dc01f60b2d3408d6e1e5c7a586519313e
--- /dev/null
+++ b/lib/protobuf/runtime/CodedReader.dart
@@ -0,0 +1,67 @@
+// 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.
+
+class CodedReader {
+ static final int DEFAULT_RECURSION_LIMIT = 64;
+ static final int DEFAULT_SIZE_LIMIT = 64 << 20;
+
+ int _bufferPos = 0;
+ int _bufferSize = 0;
+ int _bufferSizeAfterLimit = 0;
+ int _currentLimit = -1;
+ int _lastTag = 0;
+ int _recursionDepth = 0;
+ int _recursionLimit;
+ int _sizeLimit;
+ int _totalBytesRetired = 0;
+
+ CodedReader(this._recursionLimit, this._sizeLimit);
+
+ void checkLastTagWas(int value) {
+ if (_lastTag != value) {
+ throw InvalidProtocolBufferException.invalidEndTag();
+ }
+ }
+
+ int getBytesUntilLimit() =>
+ _currentLimit >= 0 ? _currentLimit - (_totalBytesRetired + _bufferPos) :
+ -1;
+
+ abstract bool isAtEnd();
+
+ /**
+ * Restores the limit to a particular absolute position as returned from
+ * [_pushLimit].
+ */
+ void _popLimit(int oldLimit) {
+ _currentLimit = oldLimit;
+ }
+
+ /**
+ * Push a new limit that includes [size] bytes past the current cursor
+ * location. The method returns the current limit (absolute position).
+ */
+ int _pushLimit(int byteLimit) {
+ if (byteLimit < 0) {
+ throw InvalidProtocolBufferException.negativeSize();
+ }
+ if (_currentLimit == -1) _enableReadAhead(byteLimit);
+ byteLimit += _bufferPos;
+ int oldLimit = _currentLimit;
+ if ((oldLimit != -1 && byteLimit > oldLimit) || byteLimit > _sizeLimit) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+ _currentLimit = byteLimit;
+ return oldLimit;
+ }
+
+ void _enableReadAhead(int numberOfBytes) {}
+
+ void _checkLimit() {
+ if ((_currentLimit != -1 && _bufferPos > _currentLimit) ||
+ _bufferPos > _sizeLimit) {
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+ }
+}
« no previous file with comments | « lib/protobuf/runtime/CodedBufferWriter.dart ('k') | lib/protobuf/runtime/CodedStreamReader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698