OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.convert; | 5 part of dart.convert; |
6 | 6 |
7 /** | 7 /** |
8 * A [Codec] encodes and (if supported) decodes data. | 8 * A [Codec] encodes and (if supported) decodes data. |
9 * | 9 * |
10 * Codecs can be fused. For example fusing [JSON] and [UTF8] produces | 10 * Codecs can be fused. For example fusing [JSON] and [UTF8] produces |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 * var decoded = JSON_TO_BYTES.decode(bytes); | 55 * var decoded = JSON_TO_BYTES.decode(bytes); |
56 * assert(decoded is List && decoded[0] == "json-object"); | 56 * assert(decoded is List && decoded[0] == "json-object"); |
57 * | 57 * |
58 * var inverted = JSON.inverted; | 58 * var inverted = JSON.inverted; |
59 * var jsonIdentity = JSON.fuse(inverted); | 59 * var jsonIdentity = JSON.fuse(inverted); |
60 * var jsonObject = jsonIdentity.encode(["1", 2]); | 60 * var jsonObject = jsonIdentity.encode(["1", 2]); |
61 * assert(jsonObject is List && jsonObject[0] == "1" && jsonObject[1] == 2
); | 61 * assert(jsonObject is List && jsonObject[0] == "1" && jsonObject[1] == 2
); |
62 */ | 62 */ |
63 // TODO(floitsch): use better example with line-splitter once that one is | 63 // TODO(floitsch): use better example with line-splitter once that one is |
64 // in this library. | 64 // in this library. |
65 Codec<S, dynamic> fuse(Codec<T, dynamic> other) { | 65 Codec<S, dynamic/*=R*/> fuse/*<R>*/(Codec<T, dynamic/*=R*/> other) { |
66 return new _FusedCodec<S, T, dynamic>(this, other); | 66 return new _FusedCodec<S, T, dynamic/*=R*/>(this, other); |
67 } | 67 } |
68 | 68 |
69 /** | 69 /** |
70 * Inverts `this`. | 70 * Inverts `this`. |
71 * | 71 * |
72 * The [encoder] and [decoder] of the resulting codec are swapped. | 72 * The [encoder] and [decoder] of the resulting codec are swapped. |
73 */ | 73 */ |
74 Codec<T, S> get inverted => new _InvertedCodec<T, S>(this); | 74 Codec<T, S> get inverted => new _InvertedCodec<T, S>(this); |
75 } | 75 } |
76 | 76 |
(...skipping 16 matching lines...) Expand all Loading... |
93 class _InvertedCodec<T, S> extends Codec<T, S> { | 93 class _InvertedCodec<T, S> extends Codec<T, S> { |
94 final Codec<S, T> _codec; | 94 final Codec<S, T> _codec; |
95 | 95 |
96 _InvertedCodec(Codec<S, T> codec) : _codec = codec; | 96 _InvertedCodec(Codec<S, T> codec) : _codec = codec; |
97 | 97 |
98 Converter<T, S> get encoder => _codec.decoder; | 98 Converter<T, S> get encoder => _codec.decoder; |
99 Converter<S, T> get decoder => _codec.encoder; | 99 Converter<S, T> get decoder => _codec.encoder; |
100 | 100 |
101 Codec<S, T> get inverted => _codec; | 101 Codec<S, T> get inverted => _codec; |
102 } | 102 } |
OLD | NEW |