UNPKG

mosx

Version:

Multiview observable state management engine

50 lines (49 loc) 1.37 kB
/// <reference types="node" /> import { ITreeNode, IReversibleJsonPatch } from "../internal"; import { Serializer } from "."; export interface ILightSchema { [name: string]: ISchemaItem; } export interface ISchemaItem { index: number; parent: string; props: string[]; schema: IPropsSchema; } export interface IPropsSchema { [prop: string]: string | IPropSchema; } export interface IPropSchema { type: "map" | "set" | "array"; items: string; } export declare class LightSerializer extends Serializer { private _schema; onCreate(): void; private entryTypePath; /** * light compression * | | 0 | 1 | 2...n+2 | n+3... | * |------|----|----|---------|----------------------------| * | byte | op | n | path | [params, value, oldValue]* | * * op: * 0 -> "add" * 1 -> "replace" * 2 -> "remove" * * n: length of path * * path: * first byte >= 0 -> typeIndex, second byte -> propIndex * first byte < 0 -> param * * "*" - encoded with notepack */ encodePatch(patch: IReversibleJsonPatch, entry: ITreeNode): Buffer; private typePropIndex; decodePatch(buffer: Buffer): IReversibleJsonPatch; private propName; encodeSnapshot(value: any): Buffer; decodeSnapshot(buffer: Buffer): any; }