метод fuse< R>
-
Codec<
T, R> other
Объединяет this с other.
При кодировании результирующий кодек выполняет кодирование с помощью this, прежде чем кодировать с помощью other.
При декодировании результирующий кодек выполняет декодирование с помощью other, прежде чем декодировать с помощью this.
В некоторых случаях для правильного объединения кодеков необходимо использовать инвертированные кодеки. То есть тип выходных данных this (T) должен соответствовать типу входных данных второго кодека other.
Примеры:
final jsonToBytes = json.fuse(utf8); List<int> bytes = jsonToBytes.encode(["json-object"]); var decoded = jsonToBytes.decode(bytes); assert(decoded is List && decoded[0] == "json-object"); var inverted = json.inverted; var jsonIdentity = json.fuse(inverted); var jsonObject = jsonIdentity.encode(["1", 2]); assert(jsonObject is List && jsonObject[0] == "1" && jsonObject[1] == 2);
Реализация
// TODO(floitsch): use better example with line-splitter once that one is
// in this library.
Codec<S, R> fuse<R>(Codec<T, R> other) {
return _FusedCodec<S, T, R>(this, other);
}
© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.19.6/dart-convert/Codec/fuse.html