UNPKG

@adguard/agtree

Version:
46 lines (43 loc) 1.71 kB
/* * AGTree v3.2.2 (build date: Tue, 08 Jul 2025 13:39:47 GMT) * (c) 2025 Adguard Software Ltd. * Released under the MIT license * https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme */ import { NULL } from '../utils/constants.js'; import { isUndefined } from '../utils/type-guards.js'; import { BaseSerializer } from './base-serializer.js'; import { RuleSerializer } from './rule-serializer.js'; import { FilterListNodeMarshallingMap } from '../marshalling-utils/filter-list-common.js'; import { BinaryTypeMarshallingMap } from '../marshalling-utils/misc/binary-type-common.js'; /** * Serializes filter list nodes to binary format. */ class FilterListSerializer extends BaseSerializer { /** * Serializes a filter list node to binary format. * * @param node Node to serialize. * @param buffer ByteBuffer for writing binary data. */ // TODO: add support for raws, if ever needed static serialize(node, buffer) { buffer.writeUint8(BinaryTypeMarshallingMap.FilterListNode); buffer.writeUint8(FilterListNodeMarshallingMap.Children); const count = node.children.length; buffer.writeUint32(count); for (let i = 0; i < count; i += 1) { RuleSerializer.serialize(node.children[i], buffer); } if (!isUndefined(node.start)) { buffer.writeUint8(FilterListNodeMarshallingMap.Start); buffer.writeUint32(node.start); } if (!isUndefined(node.end)) { buffer.writeUint8(FilterListNodeMarshallingMap.End); buffer.writeUint32(node.end); } buffer.writeUint8(NULL); } } export { FilterListSerializer };