/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v5.108.3
lib/serialization/ArraySerializer.js
36 строк
930 B
Alexander Akait
Type serializer read/write contexts with positional tuples (#21201)
18 июн 2026, 00:07
Не верифицирован
18 июн 2026, 00:07
907d23f
Код
Авторство
О чём код?
/* MIT License http://www.opensource.org/licenses/mit-license.php */ "use strict"; class ArraySerializer { /** * Serializes this instance into the provided serializer context. * @template T * @param {T[]} array array * @param {import("./ObjectMiddleware").ObjectSerializerContext<(number | T)[]>} context context */ serialize(array, context) { context.write(array.length); for (const item of array) context.write(item); } /** * Restores this instance from the provided deserializer context. * @template T * @param {import("./ObjectMiddleware").ObjectDeserializerContext<(number | T)[]>} context context * @returns {T[]} array */ deserialize(context) { const length = /** @type {number} */ (context.read()); /** @type {T[]} */ const array = []; for (let i = 0; i < length; i++) { array.push(/** @type {T} */ (context.read())); } return array; } } module.exports = ArraySerializer;