{"version":3,"file":"SchemaSerializer.mjs","sources":["../../../../src/serializer/SchemaSerializer.ts"],"sourcesContent":["import { Serializer } from \"./Serializer\";\nimport { Schema, Reflection, Iterator } from \"@colyseus/schema\";\n\nexport type SchemaConstructor<T = Schema> = new (...args: any[]) => T;\n\nexport class SchemaSerializer<T extends Schema = any> implements Serializer<T> {\n    state: T;\n\n    setState(rawState: any): void {\n        this.state.decode(rawState);\n    }\n\n    getState() {\n        return this.state;\n    }\n\n    patch(patches) {\n        this.state.decode(patches);\n    }\n\n    teardown() {\n        this.state?.['$changes']?.root.clearRefs();\n    }\n\n    handshake(bytes: number[], it?: Iterator) {\n        if (this.state) {\n            // validate client/server definitinos\n            const reflection = new Reflection();\n            reflection.decode(bytes, it);\n\n        } else {\n            // initialize reflected state from server\n            this.state = Reflection.decode(bytes, it) as any;\n        }\n    }\n}\n"],"names":[],"mappings":";;;MAKa,gBAAgB,CAAA;AACzB,IAAA,KAAK,CAAI;AAET,IAAA,QAAQ,CAAC,QAAa,EAAA;AAClB,QAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;KAC/B;IAED,QAAQ,GAAA;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;KACrB;AAED,IAAA,KAAK,CAAC,OAAO,EAAA;AACT,QAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;KAC9B;IAED,QAAQ,GAAA;QACJ,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;KAC9C;IAED,SAAS,CAAC,KAAe,EAAE,EAAa,EAAA;QACpC,IAAI,IAAI,CAAC,KAAK,EAAE;;AAEZ,YAAA,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;AACpC,YAAA,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAEhC,SAAA;AAAM,aAAA;;YAEH,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAQ,CAAC;AACpD,SAAA;KACJ;AACJ;;;;"}