| 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 // TODO(jimhug): Fill out methods, add encoder, move to shared lib. | |
| 6 class Decoder { | |
| 7 int index; | |
| 8 String data; | |
| 9 | |
| 10 Decoder(this.data) { | |
| 11 this.index = 0; | |
| 12 } | |
| 13 | |
| 14 // Reads numbers in variable-length 7-bit encoding. This matches the | |
| 15 // varint encoding used by protobufs except that it only uses 7 | |
| 16 // bits per byte so it can be efficiently passed as UTF8. | |
| 17 // For more info, see appengine/encoder.py. | |
| 18 int readInt() { | |
| 19 var r = 0; | |
| 20 for (var i=0; ; i++) { | |
| 21 var v = data.charCodeAt(index++); | |
| 22 r |= (v & 0x3F) << (6 * i); | |
| 23 if ((v & 0x40) == 0) break; | |
| 24 } | |
| 25 return r.toInt(); | |
| 26 } | |
| 27 | |
| 28 bool readBool() { | |
| 29 final ch = data[index++]; | |
| 30 assert (ch == 'T' || ch == 'F'); | |
| 31 return ch == 'T'; | |
| 32 } | |
| 33 | |
| 34 String readString() { | |
| 35 int len = readInt(); | |
| 36 String s = data.substring(index, index+len); | |
| 37 index += len; | |
| 38 return s; | |
| 39 } | |
| 40 } | |
| 41 | |
| OLD | NEW |