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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 int readSfixed32() => _readByteData(4).getInt32(0, Endianness.LITTLE_ENDIAN); | 120 int readSfixed32() => _readByteData(4).getInt32(0, Endianness.LITTLE_ENDIAN); |
121 Int64 readSfixed64() { | 121 Int64 readSfixed64() { |
122 var data = _readByteData(8); | 122 var data = _readByteData(8); |
123 var view = new Uint8List.view(data.buffer, data.offsetInBytes, 8); | 123 var view = new Uint8List.view(data.buffer, data.offsetInBytes, 8); |
124 return new Int64.fromBytes(view); | 124 return new Int64.fromBytes(view); |
125 } | 125 } |
126 bool readBool() => _readRawVarint32() != 0; | 126 bool readBool() => _readRawVarint32() != 0; |
127 List<int> readBytes() { | 127 List<int> readBytes() { |
128 int length = readInt32(); | 128 int length = readInt32(); |
129 _checkLimit(length); | 129 _checkLimit(length); |
130 return new Uint8List.view(_buffer.buffer, _bufferPos - length, length); | 130 return new Uint8List.view(_buffer.buffer, |
| 131 _buffer.offsetInBytes + _bufferPos - length, length); |
131 } | 132 } |
132 String readString() => _UTF8.decode(readBytes()); | 133 String readString() => _UTF8.decode(readBytes()); |
133 double readFloat() => | 134 double readFloat() => |
134 _readByteData(4).getFloat32(0, Endianness.LITTLE_ENDIAN); | 135 _readByteData(4).getFloat32(0, Endianness.LITTLE_ENDIAN); |
135 double readDouble() => | 136 double readDouble() => |
136 _readByteData(8).getFloat64(0, Endianness.LITTLE_ENDIAN); | 137 _readByteData(8).getFloat64(0, Endianness.LITTLE_ENDIAN); |
137 | 138 |
138 int readTag() { | 139 int readTag() { |
139 if (isAtEnd()) { | 140 if (isAtEnd()) { |
140 _lastTag = 0; | 141 _lastTag = 0; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 for (int i = 0; i < 5; i++) { | 204 for (int i = 0; i < 5; i++) { |
204 int byte = _readRawVarintByte(); | 205 int byte = _readRawVarintByte(); |
205 hi |= (byte & 0x7f) << ((i * 7) + 3); | 206 hi |= (byte & 0x7f) << ((i * 7) + 3); |
206 if ((byte & 0x80) == 0) return new Int64.fromInts(hi, lo); | 207 if ((byte & 0x80) == 0) return new Int64.fromInts(hi, lo); |
207 } | 208 } |
208 throw new InvalidProtocolBufferException.malformedVarint(); | 209 throw new InvalidProtocolBufferException.malformedVarint(); |
209 } | 210 } |
210 | 211 |
211 ByteData _readByteData(int sizeInBytes) { | 212 ByteData _readByteData(int sizeInBytes) { |
212 _checkLimit(sizeInBytes); | 213 _checkLimit(sizeInBytes); |
213 return new ByteData.view( | 214 return new ByteData.view(_buffer.buffer, |
214 _buffer.buffer, _bufferPos - sizeInBytes, sizeInBytes); | 215 _buffer.offsetInBytes + _bufferPos - sizeInBytes, sizeInBytes); |
215 } | 216 } |
216 } | 217 } |
OLD | NEW |