OLD | NEW |
1 part of serialization; | 1 part of serialization; |
2 | 2 |
3 /** | 3 /** |
4 * An abstract class for serialization formats. Subclasses define how data | 4 * An abstract class for serialization formats. Subclasses define how data |
5 * is read or written to a particular output mechanism. | 5 * is read or written to a particular output mechanism. |
6 */ | 6 */ |
7 abstract class Format { | 7 abstract class Format { |
8 /** | 8 /** |
9 * Return true if this format stores primitives in their own area and uses | 9 * Return true if this format stores primitives in their own area and uses |
10 * references to them (e.g. [SimpleFlatFormat]) and false if primitives | 10 * references to them (e.g. [SimpleFlatFormat]) and false if primitives |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 * and return the Map representation that the reader expects, with top-level | 154 * and return the Map representation that the reader expects, with top-level |
155 * entries for "rules", "data", and "roots". Nested lists/maps will be | 155 * entries for "rules", "data", and "roots". Nested lists/maps will be |
156 * converted into Reference objects. Note that if the data was not written | 156 * converted into Reference objects. Note that if the data was not written |
157 * with [storeRoundTripInfo] true this will fail. | 157 * with [storeRoundTripInfo] true this will fail. |
158 */ | 158 */ |
159 Map<String, dynamic> read(String input, Reader r) { | 159 Map<String, dynamic> read(String input, Reader r) { |
160 var data = json.parse(input); | 160 var data = json.parse(input); |
161 var result = {}; | 161 var result = {}; |
162 result["rules"] = null; | 162 result["rules"] = null; |
163 var ruleData = | 163 var ruleData = |
164 new List(r.serialization.rules.length).mappedBy((x) => []).toList(); | 164 new List(r.serialization.rules.length).map((x) => []).toList(); |
165 var top = recursivelyFixUp(data, r, ruleData); | 165 var top = recursivelyFixUp(data, r, ruleData); |
166 result["data"] = ruleData; | 166 result["data"] = ruleData; |
167 result["roots"] = [top]; | 167 result["roots"] = [top]; |
168 return result; | 168 return result; |
169 } | 169 } |
170 | 170 |
171 /** | 171 /** |
172 * Convert nested references in [data] into [Reference] objects. | 172 * Convert nested references in [data] into [Reference] objects. |
173 */ | 173 */ |
174 recursivelyFixUp(data, Reader r, List result) { | 174 recursivelyFixUp(data, Reader r, List result) { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } else { | 427 } else { |
428 return new Reference(r, a, b); | 428 return new Reference(r, a, b); |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 /** Return the next element from the input. */ | 432 /** Return the next element from the input. */ |
433 _next(Iterator input) { | 433 _next(Iterator input) { |
434 input.moveNext(); | 434 input.moveNext(); |
435 return input.current; | 435 return input.current; |
436 } | 436 } |
437 } | 437 } |
OLD | NEW |