Метод fuse
Codec<S, R> fuse<R>(Объединяет this с other.
При кодировании результирующий кодек кодирует с помощью this перед кодированием с помощью other.
При декодировании результирующий кодек декодирует с помощью other перед декодированием с помощью this.
В некоторых случаях необходимо использовать инвертированные кодеки, чтобы правильно их объединить. То есть, тип выходных данных this (T) должен соответствовать типу входных данных второго кодека other.
Примеры:
final JSON_TO_BYTES = JSON.fuse(UTF8); List<int> bytes = JSON_TO_BYTES.encode(["json-object"]); var decoded = JSON_TO_BYTES.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 new _FusedCodec<S, T, R>(this, other);
}
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-convert/Codec/fuse.html