| Index: sdk/lib/codec/codec.dart
|
| diff --git a/sdk/lib/codec/codec.dart b/sdk/lib/codec/codec.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d19525279b04765af2bfd80765708aec90f3923a
|
| --- /dev/null
|
| +++ b/sdk/lib/codec/codec.dart
|
| @@ -0,0 +1,46 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library dart.codec;
|
| +
|
| +import 'dart:convert';
|
| +
|
| +part 'encoding.dart';
|
| +part 'json.dart';
|
| +part 'line_splitter.dart';
|
| +
|
| +abstract class Codec<S, T> {
|
| + const Codec();
|
| +
|
| + T encode(S input) => encoder.convert(input);
|
| + S decode(T encoded) => decoder.convert(encoded);
|
| +
|
| + Converter<S, T> get encoder;
|
| + Converter<T, S> get decoder;
|
| +
|
| + Codec<S, dynamic> fuse(Codec<T, dynamic> other) {
|
| + return new FusedCodec<S, T, dynamic>(this, other);
|
| + }
|
| +}
|
| +
|
| +class FusedCodec<S, M, T> extends Codec<S, T> {
|
| + final Codec<S, M> first;
|
| + final Codec<M, T> second;
|
| +
|
| + Converter get encoder => first.encoder.fuse(second.encoder);
|
| + Converter get decoder => second.decoder.fuse(first.decoder);
|
| +
|
| + FusedCodec(Codec<S, M> first, Codec<M, T> second)
|
| + : this.first = first,
|
| + this.second = second;
|
| +}
|
| +
|
| +class InvertedCodec<S, T> extends Codec<S, T> {
|
| + final Codec<T, S> _codec;
|
| +
|
| + InvertedCodec(Codec<T, S> codec) : _codec = codec;
|
| +
|
| + Converter get encoder => _codec.decoder;
|
| + Converter get decoder => _codec.encoder;
|
| +}
|
|
|