OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of protobuf; | 5 part of protobuf; |
6 | 6 |
7 class CodedBufferReader { | 7 class CodedBufferReader { |
8 static const int DEFAULT_RECURSION_LIMIT = 64; | 8 static const int DEFAULT_RECURSION_LIMIT = 64; |
9 static const int DEFAULT_SIZE_LIMIT = 64 << 20; | 9 static const int DEFAULT_SIZE_LIMIT = 64 << 20; |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 void _checkLimit(int increment) { | 56 void _checkLimit(int increment) { |
57 assert(_currentLimit != -1); | 57 assert(_currentLimit != -1); |
58 _bufferPos += increment; | 58 _bufferPos += increment; |
59 if (_bufferPos > _currentLimit) { | 59 if (_bufferPos > _currentLimit) { |
60 throw new InvalidProtocolBufferException.truncatedMessage(); | 60 throw new InvalidProtocolBufferException.truncatedMessage(); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 bool _canRead(int increment) => _bufferPos + increment <= _currentLimit; | |
65 | |
66 void readGroup(int fieldNumber, GeneratedMessage message, | 64 void readGroup(int fieldNumber, GeneratedMessage message, |
67 ExtensionRegistry extensionRegistry) { | 65 ExtensionRegistry extensionRegistry) { |
68 if (_recursionDepth >= _recursionLimit) { | 66 if (_recursionDepth >= _recursionLimit) { |
69 throw new InvalidProtocolBufferException.recursionLimitExceeded(); | 67 throw new InvalidProtocolBufferException.recursionLimitExceeded(); |
70 } | 68 } |
71 ++_recursionDepth; | 69 ++_recursionDepth; |
72 message.mergeFromCodedBufferReader(this); | 70 message.mergeFromCodedBufferReader(this); |
73 checkLastTagWas(makeTag(fieldNumber, WIRETYPE_END_GROUP)); | 71 checkLastTagWas(makeTag(fieldNumber, WIRETYPE_END_GROUP)); |
74 --_recursionDepth; | 72 --_recursionDepth; |
75 } | 73 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 207 } |
210 throw new InvalidProtocolBufferException.malformedVarint(); | 208 throw new InvalidProtocolBufferException.malformedVarint(); |
211 } | 209 } |
212 | 210 |
213 ByteData _readByteData(int sizeInBytes) { | 211 ByteData _readByteData(int sizeInBytes) { |
214 _checkLimit(sizeInBytes); | 212 _checkLimit(sizeInBytes); |
215 return new ByteData.view( | 213 return new ByteData.view( |
216 _buffer.buffer, _bufferPos - sizeInBytes, sizeInBytes); | 214 _buffer.buffer, _bufferPos - sizeInBytes, sizeInBytes); |
217 } | 215 } |
218 } | 216 } |
OLD | NEW |