@@ -7,6 +7,7 @@ import 'dart:convert';
7
7
import 'package:build/build.dart' hide Builder;
8
8
import 'package:built_collection/built_collection.dart' ;
9
9
import 'package:built_value/built_value.dart' ;
10
+ import 'package:built_value/serializer.dart' ;
10
11
import 'package:crypto/crypto.dart' ;
11
12
import 'package:glob/glob.dart' ;
12
13
@@ -16,6 +17,8 @@ part 'node.g.dart';
16
17
17
18
/// Types of [AssetNode] .
18
19
class NodeType extends EnumClass {
20
+ static Serializer <NodeType > get serializer => _$nodeTypeSerializer;
21
+
19
22
static const NodeType builderOptions = _$builderOptions;
20
23
static const NodeType generated = _$generated;
21
24
static const NodeType glob = _$glob;
@@ -33,6 +36,8 @@ class NodeType extends EnumClass {
33
36
34
37
/// A node in the asset graph which may be an input to other assets.
35
38
abstract class AssetNode implements Built <AssetNode , AssetNodeBuilder > {
39
+ static Serializer <AssetNode > get serializer => _$assetNodeSerializer;
40
+
36
41
AssetId get id;
37
42
NodeType get type;
38
43
@@ -313,6 +318,9 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
313
318
abstract class GeneratedNodeConfiguration
314
319
implements
315
320
Built <GeneratedNodeConfiguration , GeneratedNodeConfigurationBuilder > {
321
+ static Serializer <GeneratedNodeConfiguration > get serializer =>
322
+ _$generatedNodeConfigurationSerializer;
323
+
316
324
/// The primary input which generated this node.
317
325
AssetId get primaryInput;
318
326
@@ -342,6 +350,9 @@ abstract class GeneratedNodeConfiguration
342
350
/// State for an [AssetNode.generated] that changes during the build.
343
351
abstract class GeneratedNodeState
344
352
implements Built <GeneratedNodeState , GeneratedNodeStateBuilder > {
353
+ static Serializer <GeneratedNodeState > get serializer =>
354
+ _$generatedNodeStateSerializer;
355
+
345
356
/// All the inputs that were read when generating this asset, or deciding not
346
357
/// to generate it.
347
358
BuiltSet <AssetId > get inputs;
@@ -373,6 +384,9 @@ abstract class GeneratedNodeState
373
384
/// Additional configuration for an [AssetNode.glob] .
374
385
abstract class GlobNodeConfiguration
375
386
implements Built <GlobNodeConfiguration , GlobNodeConfigurationBuilder > {
387
+ static Serializer <GlobNodeConfiguration > get serializer =>
388
+ _$globNodeConfigurationSerializer;
389
+
376
390
Glob get glob;
377
391
int get phaseNumber;
378
392
@@ -386,6 +400,10 @@ abstract class GlobNodeConfiguration
386
400
/// State for an [AssetNode.glob] that changes during the build.
387
401
abstract class GlobNodeState
388
402
implements Built <GlobNodeState , GlobNodeStateBuilder > {
403
+ static Serializer <GlobNodeState > get serializer => _$globNodeStateSerializer;
404
+
405
+ /// The next work that needs doing on this node.
406
+
389
407
/// All the potential inputs matching this glob.
390
408
///
391
409
/// This field differs from [results] in that [AssetNode.generated] which may
@@ -412,6 +430,9 @@ abstract class PostProcessAnchorNodeConfiguration
412
430
PostProcessAnchorNodeConfiguration ,
413
431
PostProcessAnchorNodeConfigurationBuilder
414
432
> {
433
+ static Serializer <PostProcessAnchorNodeConfiguration > get serializer =>
434
+ _$postProcessAnchorNodeConfigurationSerializer;
435
+
415
436
int get actionNumber;
416
437
AssetId get builderOptionsId;
417
438
AssetId get primaryInput;
@@ -427,6 +448,9 @@ abstract class PostProcessAnchorNodeConfiguration
427
448
abstract class PostProcessAnchorNodeState
428
449
implements
429
450
Built <PostProcessAnchorNodeState , PostProcessAnchorNodeStateBuilder > {
451
+ static Serializer <PostProcessAnchorNodeState > get serializer =>
452
+ _$postProcessAnchorNodeStateSerializer;
453
+
430
454
Digest ? get previousInputsDigest;
431
455
432
456
factory PostProcessAnchorNodeState (
@@ -438,6 +462,9 @@ abstract class PostProcessAnchorNodeState
438
462
439
463
/// Work that needs doing for a node that tracks its inputs.
440
464
class PendingBuildAction extends EnumClass {
465
+ static Serializer <PendingBuildAction > get serializer =>
466
+ _$pendingBuildActionSerializer;
467
+
441
468
static const PendingBuildAction none = _$none;
442
469
static const PendingBuildAction buildIfInputsChanged = _$buildIfInputsChanged;
443
470
static const PendingBuildAction build = _$build;
@@ -448,3 +475,83 @@ class PendingBuildAction extends EnumClass {
448
475
static PendingBuildAction valueOf (String name) =>
449
476
_$pendingBuildActionValueOf (name);
450
477
}
478
+
479
+ @SerializersFor ([AssetNode ])
480
+ final Serializers serializers =
481
+ (_$serializers.toBuilder ()
482
+ ..add (AssetIdSerializer ())
483
+ ..add (DigestSerializer ())
484
+ ..add (GlobSerializer ()))
485
+ .build ();
486
+
487
+ /// Serializer for [AssetId] .
488
+ ///
489
+ /// It would also work to make `AssetId` a `built_value` class, but there's
490
+ /// little benefit and it's nicer to keep codegen local to this package.
491
+ class AssetIdSerializer implements PrimitiveSerializer <AssetId > {
492
+ @override
493
+ Iterable <Type > get types => [AssetId ];
494
+
495
+ @override
496
+ String get wireName => 'AssetId' ;
497
+
498
+ @override
499
+ AssetId deserialize (
500
+ Serializers serializers,
501
+ Object serialized, {
502
+ FullType specifiedType = FullType .unspecified,
503
+ }) => AssetId .parse (serialized as String );
504
+
505
+ @override
506
+ Object serialize (
507
+ Serializers serializers,
508
+ AssetId object, {
509
+ FullType specifiedType = FullType .unspecified,
510
+ }) => object.toString ();
511
+ }
512
+
513
+ /// Serializer for [Digest] .
514
+ class DigestSerializer implements PrimitiveSerializer <Digest > {
515
+ @override
516
+ Iterable <Type > get types => [Digest ];
517
+
518
+ @override
519
+ String get wireName => 'Digest' ;
520
+
521
+ @override
522
+ Digest deserialize (
523
+ Serializers serializers,
524
+ Object serialized, {
525
+ FullType specifiedType = FullType .unspecified,
526
+ }) => Digest (base64.decode (serialized as String ));
527
+
528
+ @override
529
+ Object serialize (
530
+ Serializers serializers,
531
+ Digest object, {
532
+ FullType specifiedType = FullType .unspecified,
533
+ }) => base64.encode (object.bytes);
534
+ }
535
+
536
+ /// Serializer for [Glob] .
537
+ class GlobSerializer implements PrimitiveSerializer <Glob > {
538
+ @override
539
+ Iterable <Type > get types => [Glob ];
540
+
541
+ @override
542
+ String get wireName => 'Glob' ;
543
+
544
+ @override
545
+ Glob deserialize (
546
+ Serializers serializers,
547
+ Object serialized, {
548
+ FullType specifiedType = FullType .unspecified,
549
+ }) => Glob (serialized as String );
550
+
551
+ @override
552
+ Object serialize (
553
+ Serializers serializers,
554
+ Glob object, {
555
+ FullType specifiedType = FullType .unspecified,
556
+ }) => object.pattern;
557
+ }
0 commit comments