5
5
part of '../api/asset.dart' ;
6
6
7
7
abstract final class LinkModeImpl implements LinkMode {
8
- /// Serialization of v1.1.0 and newer
8
+ /// Serialization of a link mode.
9
9
///
10
10
/// Does not include the toplevel keys.
11
11
///
@@ -15,30 +15,14 @@ abstract final class LinkModeImpl implements LinkMode {
15
15
/// ```
16
16
Map <String , Object > toJson ();
17
17
18
- /// Backwards compatibility with v1.0.0 of the protocol
19
- ///
20
- /// Includes the parent keys.
21
- ///
22
- /// ```
23
- /// link_mode: dynamic
24
- /// path:
25
- /// path_type: system
26
- /// uri: ${foo3Uri.toFilePath()}
27
- /// ```
28
- Map <String , Object > toJsonV1_0_0 (Uri ? file);
29
-
30
18
factory LinkModeImpl (String type, Uri ? uri) {
31
19
switch (type) {
32
- case DynamicLoadingBundledImpl ._typeValueV1_0_0:
33
20
case DynamicLoadingBundledImpl ._typeValue:
34
21
return DynamicLoadingBundledImpl ();
35
- case DynamicLoadingSystemImpl ._typeValueV1_0_0:
36
22
case DynamicLoadingSystemImpl ._typeValue:
37
23
return DynamicLoadingSystemImpl (uri! );
38
- case LookupInExecutableImpl ._typeValueV1_0_0:
39
24
case LookupInExecutableImpl ._typeValue:
40
25
return LookupInExecutableImpl ();
41
- case LookupInProcessImpl ._typeValueV1_0_0:
42
26
case LookupInProcessImpl ._typeValue:
43
27
return LookupInProcessImpl ();
44
28
case StaticLinkingImpl ._typeValue:
@@ -47,7 +31,6 @@ abstract final class LinkModeImpl implements LinkMode {
47
31
throw FormatException ('Unknown type: $type .' );
48
32
}
49
33
50
- /// v1.1.0 and newer.
51
34
factory LinkModeImpl .fromJson (Map <Object ?, Object ?> jsonMap) {
52
35
final type = get <String >(jsonMap, _typeKey);
53
36
final uriString = get <String ?>(jsonMap, _uriKey);
@@ -61,11 +44,8 @@ abstract final class LinkModeImpl implements LinkMode {
61
44
62
45
abstract final class DynamicLoadingImpl
63
46
implements LinkModeImpl , DynamicLoading {
64
- static const _pathTypeKeyV1_0_0 = 'path_type' ;
65
47
static const _typeKey = 'type' ;
66
48
static const _uriKey = 'uri' ;
67
-
68
- static const _typeValueV1_0_0 = 'dynamic' ;
69
49
}
70
50
71
51
final class DynamicLoadingBundledImpl
@@ -77,23 +57,13 @@ final class DynamicLoadingBundledImpl
77
57
78
58
factory DynamicLoadingBundledImpl () => _singleton;
79
59
80
- static const _typeValueV1_0_0 = 'absolute' ;
81
60
static const _typeValue = 'dynamic_loading_bundle' ;
82
61
83
62
@override
84
63
Map <String , Object > toJson () => {
85
64
DynamicLoadingImpl ._typeKey: _typeValue,
86
65
};
87
66
88
- @override
89
- Map <String , Object > toJsonV1_0_0 (Uri ? file) => {
90
- NativeCodeAssetImpl ._linkModeKey: DynamicLoadingImpl ._typeValueV1_0_0,
91
- NativeCodeAssetImpl ._pathKey: {
92
- DynamicLoadingImpl ._pathTypeKeyV1_0_0: _typeValueV1_0_0,
93
- DynamicLoadingImpl ._uriKey: file! .toFilePath (),
94
- }
95
- };
96
-
97
67
@override
98
68
String toString () => _typeValue;
99
69
}
@@ -106,23 +76,13 @@ final class DynamicLoadingSystemImpl
106
76
DynamicLoadingSystemImpl (this .uri);
107
77
108
78
static const _typeValue = 'dynamic_loading_system' ;
109
- static const _typeValueV1_0_0 = 'system' ;
110
79
111
80
@override
112
81
Map <String , Object > toJson () => {
113
82
DynamicLoadingImpl ._typeKey: _typeValue,
114
83
DynamicLoadingImpl ._uriKey: uri.toFilePath (),
115
84
};
116
85
117
- @override
118
- Map <String , Object > toJsonV1_0_0 (Uri ? file) => {
119
- NativeCodeAssetImpl ._linkModeKey: DynamicLoadingImpl ._typeValueV1_0_0,
120
- NativeCodeAssetImpl ._pathKey: {
121
- DynamicLoadingImpl ._pathTypeKeyV1_0_0: _typeValueV1_0_0,
122
- DynamicLoadingImpl ._uriKey: uri.toFilePath (),
123
- }
124
- };
125
-
126
86
@override
127
87
int get hashCode => Object .hash (uri, 133723 );
128
88
@@ -146,21 +106,12 @@ final class LookupInProcessImpl implements DynamicLoadingImpl, LookupInProcess {
146
106
factory LookupInProcessImpl () => _singleton;
147
107
148
108
static const _typeValue = 'dynamic_loading_process' ;
149
- static const _typeValueV1_0_0 = 'process' ;
150
109
151
110
@override
152
111
Map <String , Object > toJson () => {
153
112
DynamicLoadingImpl ._typeKey: _typeValue,
154
113
};
155
114
156
- @override
157
- Map <String , Object > toJsonV1_0_0 (Uri ? file) => {
158
- NativeCodeAssetImpl ._linkModeKey: DynamicLoadingImpl ._typeValueV1_0_0,
159
- NativeCodeAssetImpl ._pathKey: {
160
- DynamicLoadingImpl ._pathTypeKeyV1_0_0: _typeValueV1_0_0,
161
- }
162
- };
163
-
164
115
@override
165
116
String toString () => _typeValue;
166
117
}
@@ -174,20 +125,11 @@ final class LookupInExecutableImpl
174
125
factory LookupInExecutableImpl () => _singleton;
175
126
176
127
static const _typeValue = 'dynamic_loading_executable' ;
177
- static const _typeValueV1_0_0 = 'executable' ;
178
128
179
129
@override
180
130
Map <String , Object > toJson () => {
181
131
DynamicLoadingImpl ._typeKey: _typeValue,
182
132
};
183
-
184
- @override
185
- Map <String , Object > toJsonV1_0_0 (Uri ? file) => {
186
- NativeCodeAssetImpl ._linkModeKey: DynamicLoadingImpl ._typeValueV1_0_0,
187
- NativeCodeAssetImpl ._pathKey: {
188
- DynamicLoadingImpl ._pathTypeKeyV1_0_0: _typeValueV1_0_0,
189
- }
190
- };
191
133
}
192
134
193
135
final class StaticLinkingImpl implements LinkModeImpl , StaticLinking {
@@ -204,11 +146,6 @@ final class StaticLinkingImpl implements LinkModeImpl, StaticLinking {
204
146
DynamicLoadingImpl ._typeKey: _typeValue,
205
147
};
206
148
207
- @override
208
- Map <String , Object > toJsonV1_0_0 (Uri ? file) => {
209
- NativeCodeAssetImpl ._linkModeKey: _typeValue,
210
- };
211
-
212
149
@override
213
150
String toString () => _typeValue;
214
151
}
@@ -248,56 +185,24 @@ final class NativeCodeAssetImpl implements NativeCodeAsset, AssetImpl {
248
185
}
249
186
250
187
factory NativeCodeAssetImpl .fromJson (Map <Object ?, Object ?> jsonMap) {
251
- final LinkModeImpl linkMode;
252
188
final linkModeJson = jsonMap[_linkModeKey];
253
- if (linkModeJson is String ) {
254
- // v1.0.0
255
- if (linkModeJson == StaticLinkingImpl ._typeValue) {
256
- linkMode = StaticLinkingImpl ();
257
- } else {
258
- assert (linkModeJson == DynamicLoadingImpl ._typeValueV1_0_0);
259
- final pathJson = get <Map <Object ?, Object ?>>(jsonMap, _pathKey);
260
- final type =
261
- as < String > (pathJson[DynamicLoadingImpl ._pathTypeKeyV1_0_0]);
262
- final uriString = as < String ? > (pathJson[DynamicLoadingImpl ._uriKey]);
263
- final uri = uriString != null ? Uri (path: uriString) : null ;
264
- linkMode = LinkModeImpl (type, uri);
265
- }
266
- } else {
267
- // v1.1.0 and newer.
268
- linkMode = LinkModeImpl .fromJson (as < Map <Object ?, Object ?>> (linkModeJson));
269
- }
189
+ final linkMode =
190
+ LinkModeImpl .fromJson (as < Map <Object ?, Object ?>> (linkModeJson));
270
191
271
192
final fileString = get <String ?>(jsonMap, _fileKey);
272
193
final Uri ? file;
273
194
if (fileString != null ) {
274
195
file = Uri (path: fileString);
275
- } else if ((linkMode is DynamicLoadingBundledImpl ||
276
- linkMode is StaticLinkingImpl ) &&
277
- jsonMap[_pathKey] != null ) {
278
- // Compatibility with v1.0.0.
279
- final oldPath = as < String ? > ((jsonMap[_pathKey]
280
- as Map <Object ?, Object ?>)[DynamicLoadingImpl ._uriKey]);
281
- file = oldPath != null ? Uri (path: oldPath) : null ;
282
196
} else {
283
197
file = null ;
284
198
}
285
- final targetString = get <String ?>(jsonMap, _targetKey);
286
199
final ArchitectureImpl ? architecture;
287
- final OSImpl os;
288
- if (targetString != null ) {
289
- // Compatibility with v1.0.0.
290
- final target = Target .fromString (targetString);
291
- os = target.os;
292
- architecture = target.architecture;
200
+ final os = OSImpl .fromString (get <String >(jsonMap, _osKey));
201
+ final architectureString = get <String ?>(jsonMap, _architectureKey);
202
+ if (architectureString != null ) {
203
+ architecture = ArchitectureImpl .fromString (architectureString);
293
204
} else {
294
- os = OSImpl .fromString (get <String >(jsonMap, _osKey));
295
- final architectureString = get <String ?>(jsonMap, _architectureKey);
296
- if (architectureString != null ) {
297
- architecture = ArchitectureImpl .fromString (architectureString);
298
- } else {
299
- architecture = null ;
300
- }
205
+ architecture = null ;
301
206
}
302
207
303
208
return NativeCodeAssetImpl (
@@ -346,29 +251,19 @@ final class NativeCodeAssetImpl implements NativeCodeAsset, AssetImpl {
346
251
);
347
252
348
253
@override
349
- Map <String , Object > toJson (Version version) {
350
- if (version == Version ( 1 , 0 , 0 )) {
351
- return {
254
+ Map <String , Object > toJson (Version version) => {
255
+ if (architecture != null ) _architectureKey : architecture. toString (),
256
+ if (file != null ) _fileKey : file ! . toFilePath (),
352
257
_idKey: id,
353
- ...linkMode.toJsonV1_0_0 (file),
354
- _targetKey: Target .fromArchitectureAndOS (architecture! , os).toString (),
258
+ _linkModeKey: linkMode.toJson (),
259
+ _osKey: os.toString (),
260
+ typeKey: NativeCodeAsset .type,
355
261
}..sortOnKey ();
356
- }
357
- return {
358
- if (architecture != null ) _architectureKey: architecture.toString (),
359
- if (file != null ) _fileKey: file! .toFilePath (),
360
- _idKey: id,
361
- _linkModeKey: linkMode.toJson (),
362
- _osKey: os.toString (),
363
- typeKey: NativeCodeAsset .type,
364
- }..sortOnKey ();
365
- }
366
262
367
263
static const typeKey = 'type' ;
368
264
static const _idKey = 'id' ;
369
265
static const _linkModeKey = 'link_mode' ;
370
266
static const _pathKey = 'path' ;
371
- static const _targetKey = 'target' ;
372
267
static const _fileKey = 'file' ;
373
268
static const _osKey = 'os' ;
374
269
static const _architectureKey = 'architecture' ;
0 commit comments