Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1374)

Side by Side Diff: sdk/lib/codec/codec.dart

Issue 17580014: dart:convert library. Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/libraries.dart ('k') | sdk/lib/codec/codec_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/libraries.dart ('k') | sdk/lib/codec/codec_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698