Spec-Zone.ru › Dart 2

dart:convert

Метод fuse<R>

Codec<S, R> fuse<R>(
  1. 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.18.5/dart-convert/Codec/fuse.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API