| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library dart.codec; |
| 6 |
| 7 import 'dart:convert'; |
| 8 |
| 9 part 'encoding.dart'; |
| 10 part 'json.dart'; |
| 11 part 'line_splitter.dart'; |
| 12 |
| 13 abstract class Codec<S, T> { |
| 14 const Codec(); |
| 15 |
| 16 T encode(S input) => encoder.convert(input); |
| 17 S decode(T encoded) => decoder.convert(encoded); |
| 18 |
| 19 Converter<S, T> get encoder; |
| 20 Converter<T, S> get decoder; |
| 21 |
| 22 Codec<S, dynamic> fuse(Codec<T, dynamic> other) { |
| 23 return new FusedCodec<S, T, dynamic>(this, other); |
| 24 } |
| 25 } |
| 26 |
| 27 class FusedCodec<S, M, T> extends Codec<S, T> { |
| 28 final Codec<S, M> first; |
| 29 final Codec<M, T> second; |
| 30 |
| 31 Converter get encoder => first.encoder.fuse(second.encoder); |
| 32 Converter get decoder => second.decoder.fuse(first.decoder); |
| 33 |
| 34 FusedCodec(Codec<S, M> first, Codec<M, T> second) |
| 35 : this.first = first, |
| 36 this.second = second; |
| 37 } |
| 38 |
| 39 class InvertedCodec<S, T> extends Codec<S, T> { |
| 40 final Codec<T, S> _codec; |
| 41 |
| 42 InvertedCodec(Codec<T, S> codec) : _codec = codec; |
| 43 |
| 44 Converter get encoder => _codec.decoder; |
| 45 Converter get decoder => _codec.encoder; |
| 46 } |
| OLD | NEW |