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

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

Issue 17578002: pkg/serialization: add format param to Serialization.read method (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fewer things Created 7 years, 5 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
« no previous file with comments | « no previous file | pkg/serialization/lib/src/format.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * This provides a general-purpose serialization facility for Dart objects. A 6 * This provides a general-purpose serialization facility for Dart objects. A
7 * [Serialization] is defined in terms of [SerializationRule]s and supports 7 * [Serialization] is defined in terms of [SerializationRule]s and supports
8 * reading and writing to different formats. 8 * reading and writing to different formats.
9 * 9 *
10 * ## Installing ## 10 * ## Installing ##
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 void addRule(SerializationRule rule) { 354 void addRule(SerializationRule rule) {
355 rule.number = rules.length; 355 rule.number = rules.length;
356 rules.add(rule); 356 rules.add(rule);
357 } 357 }
358 358
359 /** 359 /**
360 * This writes out an object graph rooted at [object] and returns the result. 360 * This writes out an object graph rooted at [object] and returns the result.
361 * The [format] parameter determines the form of the result. The default 361 * The [format] parameter determines the form of the result. The default
362 * format returns a String in [json] format. 362 * format returns a String in [json] format.
363 */ 363 */
364 write(Object object, [Format format]) { 364 write(Object object, {Format format}) {
365 return newWriter(format).write(object); 365 return newWriter(format).write(object);
366 } 366 }
367 367
368 /** 368 /**
369 * Return a new [Writer] object for this serialization. This is useful if you 369 * Return a new [Writer] object for this serialization. This is useful if you
370 * want to do something more complex with the writer than just returning 370 * want to do something more complex with the writer than just returning
371 * the final result. 371 * the final result.
372 */ 372 */
373 Writer newWriter([Format format]) => 373 Writer newWriter([Format format]) => new Writer(this, format);
374 new Writer(this, format);
375 374
376 /** 375 /**
377 * Read the serialized data from [input] and return the root object 376 * Read the serialized data from [input] and return the root object
378 * from the result. The [input] can be of any type that the [Format] 377 * from the result. The [input] can be of any type that the [Format]
379 * reads/writes, but normally will be a [List], [Map], or a simple type. 378 * reads/writes, but normally will be a [List], [Map], or a simple type.
379 * The [format] parameter determines the form of the result. The default
380 * format returns a String in [json] format.
380 * If there are objects that need to be resolved 381 * If there are objects that need to be resolved
381 * in the current context, they should be provided in [externals] as a 382 * in the current context, they should be provided in [externals] as a
382 * Map from names to values. In particular, in the current implementation 383 * Map from names to values. In particular, in the current implementation
383 * any class mirrors needed should be provided in [externals] using the 384 * any class mirrors needed should be provided in [externals] using the
384 * class name as a key. In addition to the [externals] map provided here, 385 * class name as a key. In addition to the [externals] map provided here,
385 * values will be looked up in the [namedObjects] map. 386 * values will be looked up in the [namedObjects] map.
386 */ 387 */
387 read(input, [Map externals = const {}]) { 388 read(input, {Format format, Map externals: const {}}) {
388 return newReader().read(input, externals); 389 return newReader(format).read(input, externals);
389 } 390 }
390 391
391 /** 392 /**
392 * Return a new [Reader] object for this serialization. This is useful if 393 * Return a new [Reader] object for this serialization. This is useful if
393 * you want to do something more complex with the reader than just returning 394 * you want to do something more complex with the reader than just returning
394 * the final result. 395 * the final result.
395 */ 396 */
396 Reader newReader([Format format]) => new Reader(this, format); 397 Reader newReader([Format format]) => new Reader(this, format);
397 398
398 /** 399 /**
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 } 494 }
494 return ifAbsent == null ? null : ifAbsent(); 495 return ifAbsent == null ? null : ifAbsent();
495 } 496 }
496 } 497 }
497 498
498 /** 499 /**
499 * An exception class for errors during serialization. 500 * An exception class for errors during serialization.
500 */ 501 */
501 class SerializationException implements Exception { 502 class SerializationException implements Exception {
502 final String message; 503 final String message;
503 const SerializationException([this.message]); 504 const SerializationException(this.message);
504 toString() => "SerializationException($message)"; 505 String toString() => "SerializationException($message)";
505 } 506 }
OLDNEW
« no previous file with comments | « no previous file | pkg/serialization/lib/src/format.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698