import { Serializer } from "./Serializer" ; import { Schema , Reflection , Iterator } from "@colyseus/schema" ; export type SchemaConstructor < T = Schema > = new ( ... args ) => T ; export class SchemaSerializer < T extends Schema = any > implements Serializer < T > { state : T ; setState ( rawState ) { this . state . decode ( rawState ) ; } getState ( ) { return this . state ; } patch ( patches ) { this . state . decode ( patches ) ; } teardown ( ) { this . state ?. [ '$changes' ] ?. root . clearRefs ( ) ; } handshake ( bytes , it ? ) { if ( this . state ) { const reflection = new Reflection ( ) ; reflection . decode ( bytes , it ) ; } else { this . state = Reflection . decode ( bytes , it ) as any ; } } }