mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 14:24:38 +00:00
745f112ef6
Opt an initial batch of files under samples, samples-dev, utils, and runtime/tools/dartfuzz out of null safety in preparation for switching the flag on by default. Change-Id: Icdfd52a5a969e678a7205903332f73fe3841c223 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166960 Reviewed-by: Daco Harkes <dacoharkes@google.com> Commit-Queue: Leaf Petersen <leafp@google.com>
45 lines
1.1 KiB
Dart
45 lines
1.1 KiB
Dart
// 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.
|
|
|
|
// @dart = 2.9
|
|
|
|
part of swarmlib;
|
|
|
|
// TODO(jimhug): Fill out methods, add encoder, move to shared lib.
|
|
class Decoder {
|
|
int index;
|
|
String data;
|
|
|
|
Decoder(this.data) {
|
|
this.index = 0;
|
|
}
|
|
|
|
// Reads numbers in variable-length 7-bit encoding. This matches the
|
|
// varint encoding used by protobufs except that it only uses 7
|
|
// bits per byte so it can be efficiently passed as UTF8.
|
|
// For more info, see appengine/encoder.py.
|
|
int readInt() {
|
|
var r = 0;
|
|
for (var i = 0;; i++) {
|
|
var v = data.codeUnitAt(index++);
|
|
r |= (v & 0x3F) << (6 * i);
|
|
if ((v & 0x40) == 0) break;
|
|
}
|
|
return r.toInt();
|
|
}
|
|
|
|
bool readBool() {
|
|
final ch = data[index++];
|
|
assert(ch == 'T' || ch == 'F');
|
|
return ch == 'T';
|
|
}
|
|
|
|
String readString() {
|
|
int len = readInt();
|
|
String s = data.substring(index, index + len);
|
|
index += len;
|
|
return s;
|
|
}
|
|
}
|