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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 if (storeRoundTripInfo) each[RULE] = rule.number; | 147 if (storeRoundTripInfo) each[RULE] = rule.number; |
148 } | 148 } |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 /** | 152 /** |
153 * For one particular entry, which is either a Map or a List, update it | 153 * For one particular entry, which is either a Map or a List, update it |
154 * to turn References into a nested List/Map. | 154 * to turn References into a nested List/Map. |
155 */ | 155 */ |
156 jsonifyEntry(map, Writer w) { | 156 jsonifyEntry(map, Writer w) { |
| 157 // Note, if this is a Map, and the key might be a reference, we need to |
| 158 // bend over backwards to avoid concurrent modifications. Non-string keys |
| 159 // won't actually work if we try to write this to json, but might happen |
| 160 // if e.g. sending between isolates. |
| 161 var updates = new Map(); |
157 keysAndValues(map).forEach((key, value) { | 162 keysAndValues(map).forEach((key, value) { |
158 if (value is Reference) map[key] = w.stateForReference(value); | 163 if (value is Reference) updates[key] = w.stateForReference(value); |
159 }); | 164 }); |
| 165 updates.forEach((k, v) => map[k] = v); |
160 } | 166 } |
161 | 167 |
162 /** | 168 /** |
163 * Read serialized data saved in this format, which should look like | 169 * Read serialized data saved in this format, which should look like |
164 * either a simple type, a List or a Map and return the Map | 170 * either a simple type, a List or a Map and return the Map |
165 * representation that the reader expects, with top-level | 171 * representation that the reader expects, with top-level |
166 * entries for "rules", "data", and "roots". Nested lists/maps will be | 172 * entries for "rules", "data", and "roots". Nested lists/maps will be |
167 * converted into Reference objects. Note that if the data was not written | 173 * converted into Reference objects. Note that if the data was not written |
168 * with [storeRoundTripInfo] true this will fail. | 174 * with [storeRoundTripInfo] true this will fail. |
169 */ | 175 */ |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 return new Reference(r, a, b); | 462 return new Reference(r, a, b); |
457 } | 463 } |
458 } | 464 } |
459 | 465 |
460 /** Return the next element from the input. */ | 466 /** Return the next element from the input. */ |
461 _next(Iterator input) { | 467 _next(Iterator input) { |
462 input.moveNext(); | 468 input.moveNext(); |
463 return input.current; | 469 return input.current; |
464 } | 470 } |
465 } | 471 } |
OLD | NEW |