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

Side by Side Diff: samples-dev/swarm/Decoder.dart

Issue 2828603002: Format samples and samples-dev directories. (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « samples-dev/swarm/DataSource.dart ('k') | samples-dev/swarm/HelpDialog.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 swarmlib; 5 part of swarmlib;
6 6
7 // TODO(jimhug): Fill out methods, add encoder, move to shared lib. 7 // TODO(jimhug): Fill out methods, add encoder, move to shared lib.
8 class Decoder { 8 class Decoder {
9 int index; 9 int index;
10 String data; 10 String data;
11 11
12 Decoder(this.data) { 12 Decoder(this.data) {
13 this.index = 0; 13 this.index = 0;
14 } 14 }
15 15
16 // Reads numbers in variable-length 7-bit encoding. This matches the 16 // Reads numbers in variable-length 7-bit encoding. This matches the
17 // varint encoding used by protobufs except that it only uses 7 17 // varint encoding used by protobufs except that it only uses 7
18 // bits per byte so it can be efficiently passed as UTF8. 18 // bits per byte so it can be efficiently passed as UTF8.
19 // For more info, see appengine/encoder.py. 19 // For more info, see appengine/encoder.py.
20 int readInt() { 20 int readInt() {
21 var r = 0; 21 var r = 0;
22 for (var i=0; ; i++) { 22 for (var i = 0;; i++) {
23 var v = data.codeUnitAt(index++); 23 var v = data.codeUnitAt(index++);
24 r |= (v & 0x3F) << (6 * i); 24 r |= (v & 0x3F) << (6 * i);
25 if ((v & 0x40) == 0) break; 25 if ((v & 0x40) == 0) break;
26 } 26 }
27 return r.toInt(); 27 return r.toInt();
28 } 28 }
29 29
30 bool readBool() { 30 bool readBool() {
31 final ch = data[index++]; 31 final ch = data[index++];
32 assert (ch == 'T' || ch == 'F'); 32 assert(ch == 'T' || ch == 'F');
33 return ch == 'T'; 33 return ch == 'T';
34 } 34 }
35 35
36 String readString() { 36 String readString() {
37 int len = readInt(); 37 int len = readInt();
38 String s = data.substring(index, index+len); 38 String s = data.substring(index, index + len);
39 index += len; 39 index += len;
40 return s; 40 return s;
41 } 41 }
42 } 42 }
43
OLDNEW
« no previous file with comments | « samples-dev/swarm/DataSource.dart ('k') | samples-dev/swarm/HelpDialog.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698