OLD | NEW |
(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 class CodedReader { |
| 6 static final int DEFAULT_RECURSION_LIMIT = 64; |
| 7 static final int DEFAULT_SIZE_LIMIT = 64 << 20; |
| 8 |
| 9 int _bufferPos = 0; |
| 10 int _bufferSize = 0; |
| 11 int _bufferSizeAfterLimit = 0; |
| 12 int _currentLimit = -1; |
| 13 int _lastTag = 0; |
| 14 int _recursionDepth = 0; |
| 15 int _recursionLimit; |
| 16 int _sizeLimit; |
| 17 int _totalBytesRetired = 0; |
| 18 |
| 19 CodedReader(this._recursionLimit, this._sizeLimit); |
| 20 |
| 21 void checkLastTagWas(int value) { |
| 22 if (_lastTag != value) { |
| 23 throw InvalidProtocolBufferException.invalidEndTag(); |
| 24 } |
| 25 } |
| 26 |
| 27 int getBytesUntilLimit() => |
| 28 _currentLimit >= 0 ? _currentLimit - (_totalBytesRetired + _bufferPos) : |
| 29 -1; |
| 30 |
| 31 abstract bool isAtEnd(); |
| 32 |
| 33 /** |
| 34 * Restores the limit to a particular absolute position as returned from |
| 35 * [_pushLimit]. |
| 36 */ |
| 37 void _popLimit(int oldLimit) { |
| 38 _currentLimit = oldLimit; |
| 39 } |
| 40 |
| 41 /** |
| 42 * Push a new limit that includes [size] bytes past the current cursor |
| 43 * location. The method returns the current limit (absolute position). |
| 44 */ |
| 45 int _pushLimit(int byteLimit) { |
| 46 if (byteLimit < 0) { |
| 47 throw InvalidProtocolBufferException.negativeSize(); |
| 48 } |
| 49 if (_currentLimit == -1) _enableReadAhead(byteLimit); |
| 50 byteLimit += _bufferPos; |
| 51 int oldLimit = _currentLimit; |
| 52 if ((oldLimit != -1 && byteLimit > oldLimit) || byteLimit > _sizeLimit) { |
| 53 throw InvalidProtocolBufferException.truncatedMessage(); |
| 54 } |
| 55 _currentLimit = byteLimit; |
| 56 return oldLimit; |
| 57 } |
| 58 |
| 59 void _enableReadAhead(int numberOfBytes) {} |
| 60 |
| 61 void _checkLimit() { |
| 62 if ((_currentLimit != -1 && _bufferPos > _currentLimit) || |
| 63 _bufferPos > _sizeLimit) { |
| 64 throw InvalidProtocolBufferException.truncatedMessage(); |
| 65 } |
| 66 } |
| 67 } |
OLD | NEW |