This repository was archived by the owner on Oct 17, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -7,5 +7,6 @@ library convert;
7
7
export 'src/accumulator_sink.dart' ;
8
8
export 'src/byte_accumulator_sink.dart' ;
9
9
export 'src/hex.dart' ;
10
+ export 'src/identity_codec.dart' ;
10
11
export 'src/percent.dart' ;
11
12
export 'src/string_accumulator_sink.dart' ;
Original file line number Diff line number Diff line change
1
+ import 'dart:convert' ;
2
+
3
+ class _IdentityConverter <T > extends Converter <T , T > {
4
+ @override
5
+ T convert (T input) => input;
6
+ }
7
+
8
+ /// A [Codec] that converts from T to T doing absolutely nothing.
9
+ ///
10
+ /// This is the identity codec, the one that passes input to output when
11
+ /// decoding and encoding. This codec is mostly useful when implementing generic
12
+ /// code that can be fused with a [Codec] and you need an identity codec for the
13
+ /// base case.
14
+ ///
15
+ /// Note, that when fused with another [Codec] the identity codec disppears.
16
+ class IdentityCodec <T > extends Codec <T , T > {
17
+ @override
18
+ Converter <T , T > get decoder => _IdentityConverter ();
19
+ @override
20
+ Converter <T , T > get encoder => _IdentityConverter ();
21
+
22
+ /// Fuse with an other codec.
23
+ ///
24
+ /// This will return the [other] codec, as the identity codec is trivial.
25
+ @override
26
+ Codec <T , R > fuse <R >(Codec <T , R > other) => other;
27
+ }
You can’t perform that action at this time.
0 commit comments