@@ -37,34 +37,37 @@ abstract class Serializers {
37
37
///
38
38
/// A [Serializer] must have been provided for every the object uses.
39
39
///
40
- /// Types that are known statically can be provided via [genericType ] . This
40
+ /// Types that are known statically can be provided via [specifiedType ] . This
41
41
/// will reduce the amount of data needed on the wire. The exact same
42
- /// [genericType ] will be needed to deserialize.
42
+ /// [specifiedType ] will be needed to deserialize.
43
43
///
44
44
/// Create one using [SerializersBuilder] .
45
45
///
46
46
/// TODO(davidmorgan): document the wire format.
47
47
Object serialize (Object object,
48
- {GenericType genericType : const GenericType () });
48
+ {FullType specifiedType : FullType .unspecified });
49
49
50
50
/// Deserializes [serialized] .
51
51
///
52
52
/// A [Serializer] must have been provided for every the object uses.
53
53
///
54
- /// If [serialized] was produced by calling [serialize] with [genericType ] ,
55
- /// the exact same [genericType ] must be provided to deserialize.
54
+ /// If [serialized] was produced by calling [serialize] with [specifiedType ] ,
55
+ /// the exact same [specifiedType ] must be provided to deserialize.
56
56
Object deserialize (Object serialized,
57
- {GenericType genericType : const GenericType () });
57
+ {FullType specifiedType : FullType .unspecified });
58
58
59
- /// Creates a new builder for the type represented by [genericType ] .
59
+ /// Creates a new builder for the type represented by [fullType ] .
60
60
///
61
- /// For example, if [genericType ] is `BuiltList<int, String>` , returns a
61
+ /// For example, if [fullType ] is `BuiltList<int, String>` , returns a
62
62
/// `ListBuilder<int, String>` . This helps serializers to instantiate with
63
63
/// correct generic type parameters.
64
64
///
65
65
/// May return null if no matching builder factory has been added. In this
66
- /// case the serializer should fall back to `Object` .
67
- Object newBuilder (GenericType genericType);
66
+ /// case the serializer should throw a [StateError] .
67
+ Object newBuilder (FullType fullType);
68
+
69
+ /// Whether a builder for [fullType] is available via [newBuilder] .
70
+ bool hasBuilder (FullType fullType);
68
71
69
72
SerializersBuilder toBuilder ();
70
73
}
@@ -75,22 +78,35 @@ abstract class SerializersBuilder {
75
78
76
79
void add (Serializer serializer);
77
80
78
- void addBuilderFactory (GenericType genericType , Function function);
81
+ void addBuilderFactory (FullType specifiedType , Function function);
79
82
80
83
Serializers build ();
81
84
}
82
85
83
- /// A tree of [Type] instances.
84
- class GenericType {
86
+ /// A [Type] with, optionally, [FullType] generic type parameters.
87
+ ///
88
+ /// May also be [unspecified] , indicating that no type information is
89
+ /// available.
90
+ class FullType {
91
+ // An unspecified type.
92
+ static const unspecified = const FullType (null );
93
+
85
94
/// The root of the type.
86
95
final Type root;
87
96
88
97
/// Type parameters of the type.
89
- final List <GenericType > parameters;
98
+ final List <FullType > parameters;
99
+
100
+ const FullType (this .root, [this .parameters = const []]);
90
101
91
- const GenericType ([ this .root = Object , this .parameters = const []] );
102
+ bool get isUnspecified => identical (root, null );
92
103
93
- bool get isObject => root == Object ;
104
+ @override
105
+ String toString () => isUnspecified
106
+ ? 'unspecified'
107
+ : parameters.isEmpty
108
+ ? root.toString ()
109
+ : '${root .toString ()}<${parameters .join (", " )}>' ;
94
110
}
95
111
96
112
/// Serializes a single type.
@@ -118,16 +134,16 @@ abstract class Serializer<T> {
118
134
/// Serializes [object] .
119
135
///
120
136
/// Use [serializers] as needed for nested serialization. Information about
121
- /// the type being serialized is provided in [genericType ] .
137
+ /// the type being serialized is provided in [specifiedType ] .
122
138
///
123
139
/// TODO(davidmorgan): document the wire format.
124
140
Object serialize (Serializers serializers, T object,
125
- {GenericType genericType : const GenericType () });
141
+ {FullType specifiedType : FullType .unspecified });
126
142
127
143
/// Deserializes [serialized] .
128
144
///
129
145
/// Use [serializers] as needed for nested deserialization. Information about
130
- /// the type being deserialized is provided in [genericType ] .
146
+ /// the type being deserialized is provided in [specifiedType ] .
131
147
T deserialize (Serializers serializers, Object serialized,
132
- {GenericType genericType : const GenericType () });
148
+ {FullType specifiedType : FullType .unspecified });
133
149
}
0 commit comments