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

Unified Diff: pkg/serialization/lib/src/reader_writer.dart

Issue 12136002: Some fixes to work better with the services framework (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changes from review comments Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/serialization/lib/src/format.dart ('k') | pkg/serialization/lib/src/serialization_rule.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/serialization/lib/src/reader_writer.dart
diff --git a/pkg/serialization/lib/src/reader_writer.dart b/pkg/serialization/lib/src/reader_writer.dart
index 146255de438fbede1a47be0499b25e2768eaf753..2209f78f42210331b3f6d6efed51a502ae65b101 100644
--- a/pkg/serialization/lib/src/reader_writer.dart
+++ b/pkg/serialization/lib/src/reader_writer.dart
@@ -123,7 +123,7 @@ class Writer implements ReaderOrWriter {
if (rule.shouldUseReferenceFor(object, this)) {
references.putIfAbsent(object, () =>
new Reference(this, rule.number, _nextObjectNumberFor(rule)));
- var state = rule.extractState(object, trace.note);
+ var state = rule.extractState(object, trace.note, this);
_addStateForRule(rule, state);
}
}
@@ -143,7 +143,7 @@ class Writer implements ReaderOrWriter {
serializedRules() {
if (!selfDescribing) return null;
var meta = serialization.ruleSerialization();
- var writer = new Writer(meta);
+ var writer = new Writer(meta, format);
writer.selfDescribing = false;
return writer.write(serialization._rules);
}
@@ -309,15 +309,20 @@ class Reader implements ReaderOrWriter {
* Look up the reference to an external object. This can be held either in
* the reader-specific list of externals or in the serializer's
*/
- objectNamed(key) {
+ objectNamed(key, [Function ifAbsent]) {
var map = (namedObjects.containsKey(key))
? namedObjects : serialization.namedObjects;
if (!map.containsKey(key)) {
- throw 'Cannot find named object to link to: $key';
+ (ifAbsent == null ? keyNotFound : ifAbsent)(key);
}
return map[key];
}
+ void keyNotFound(key) {
+ throw new SerializationException(
+ 'Cannot find named object to link to: $key');
+ }
+
/**
* Return the list of rules to be used when writing. These come from the
* [serialization].
@@ -350,10 +355,11 @@ class Reader implements ReaderOrWriter {
* If the data we are reading from has rules written to it, read them back
* and set them as the rules we will use.
*/
- void readRules(String newRules) {
+ void readRules(newRules) {
// TODO(alanknight): Replacing the serialization is kind of confusing.
- List rulesWeRead = (newRules == null) ?
- null : serialization.ruleSerialization().read(newRules, namedObjects);
+ if (newRules == null) return;
+ var reader = serialization.ruleSerialization().newReader(format);
+ List rulesWeRead = reader.read(newRules, namedObjects);
if (rulesWeRead != null && !rulesWeRead.isEmpty) {
serialization = new Serialization.blank();
rulesWeRead.forEach(serialization.addRule);
« no previous file with comments | « pkg/serialization/lib/src/format.dart ('k') | pkg/serialization/lib/src/serialization_rule.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698