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

Side by Side Diff: pkg/serialization/lib/src/format.dart

Issue 14447008: Fix for mirror API breaking change to index libraries by URI, and clean up references in doc commen… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed a print statement, one unsaved fix. Created 7 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 | Annotate | Revision Log
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 /** 77 /**
78 * A format for "normal" [json] representation of objects. It stores 78 * A format for "normal" [json] representation of objects. It stores
79 * the fields of the objects as nested maps, and doesn't allow cycles. This can 79 * the fields of the objects as nested maps, and doesn't allow cycles. This can
80 * be useful in talking to existing APIs that expect [json] format data. The 80 * be useful in talking to existing APIs that expect [json] format data. The
81 * output will be either a simple object (string, num, bool), a List, or a Map, 81 * output will be either a simple object (string, num, bool), a List, or a Map,
82 * with nesting of those. 82 * with nesting of those.
83 * Note that since the classes of objects aren't normally stored, this isn't 83 * Note that since the classes of objects aren't normally stored, this isn't
84 * enough information to read back the objects. However, if the 84 * enough information to read back the objects. However, if the
85 * If the [storeRoundTripData] field of the format is set to true, then this 85 * If the [storeRoundTripInfo] field of the format is set to true, then this
86 * will store the rule number along with the data, allowing reconstruction. 86 * will store the rule number along with the data, allowing reconstruction.
87 */ 87 */
88 class SimpleJsonFormat extends Format { 88 class SimpleJsonFormat extends Format {
89 89
90 /** 90 /**
91 * Indicate if we should store rule numbers with map/list data so that we 91 * Indicate if we should store rule numbers with map/list data so that we
92 * will know how to reconstruct it with a read operation. If we don't, this 92 * will know how to reconstruct it with a read operation. If we don't, this
93 * will be more compliant with things that expect known format JSON as input, 93 * will be more compliant with things that expect known format JSON as input,
94 * but we won't be able to read back the objects. 94 * but we won't be able to read back the objects.
95 */ 95 */
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 var actualData = reader.selfDescribing ? data[DATA] : data; 188 var actualData = reader.selfDescribing ? data[DATA] : data;
189 reader.readRules(rules); 189 reader.readRules(rules);
190 var ruleData = new List.generate(reader.rules.length, (_) => []); 190 var ruleData = new List.generate(reader.rules.length, (_) => []);
191 var top = recursivelyFixUp(actualData, reader, ruleData); 191 var top = recursivelyFixUp(actualData, reader, ruleData);
192 result["data"] = ruleData; 192 result["data"] = ruleData;
193 result["roots"] = [top]; 193 result["roots"] = [top];
194 return result; 194 return result;
195 } 195 }
196 196
197 /** 197 /**
198 * Convert nested references in [data] into [Reference] objects. 198 * Convert nested references in [input] into [Reference] objects.
199 */ 199 */
200 recursivelyFixUp(input, Reader r, List result) { 200 recursivelyFixUp(input, Reader r, List result) {
201 var data = input; 201 var data = input;
202 if (isPrimitive(data)) { 202 if (isPrimitive(data)) {
203 result[r._primitiveRule().number].add(data); 203 result[r._primitiveRule().number].add(data);
204 return data; 204 return data;
205 } 205 }
206 var ruleNumber; 206 var ruleNumber;
207 // If we've added the rule number on as the last item in a list we have 207 // If we've added the rule number on as the last item in a list we have
208 // to get rid of it or it will be interpreted as extra data. For a map 208 // to get rid of it or it will be interpreted as extra data. For a map
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 return new Reference(r, a, b); 462 return new Reference(r, a, b);
463 } 463 }
464 } 464 }
465 465
466 /** Return the next element from the input. */ 466 /** Return the next element from the input. */
467 _next(Iterator input) { 467 _next(Iterator input) {
468 input.moveNext(); 468 input.moveNext();
469 return input.current; 469 return input.current;
470 } 470 }
471 } 471 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698