@colyseus/schema 3.0.40 → 3.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +1 -1
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +1 -1
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +1 -1
- package/lib/decoder/Decoder.js +1 -1
- package/lib/decoder/Decoder.js.map +1 -1
- package/package.json +1 -1
- package/src/decoder/Decoder.ts +1 -1
package/build/umd/index.js
CHANGED
|
@@ -4281,7 +4281,7 @@
|
|
|
4281
4281
|
// Trying to access a reference that haven't been decoded yet.
|
|
4282
4282
|
//
|
|
4283
4283
|
if (!nextRef) {
|
|
4284
|
-
console.error(`"refId" not found: ${nextRefId}`, { previousRef:
|
|
4284
|
+
console.error(`"refId" not found: ${nextRefId}`, { previousRef: ref, previousRefId: this.currentRefId });
|
|
4285
4285
|
console.warn("Please report this to the developers. All refIds =>");
|
|
4286
4286
|
console.warn(Schema.debugRefIdsDecoder(this));
|
|
4287
4287
|
this.skipCurrentStructure(bytes, it, totalBytes);
|
package/lib/decoder/Decoder.js
CHANGED
|
@@ -41,7 +41,7 @@ class Decoder {
|
|
|
41
41
|
// Trying to access a reference that haven't been decoded yet.
|
|
42
42
|
//
|
|
43
43
|
if (!nextRef) {
|
|
44
|
-
console.error(`"refId" not found: ${nextRefId}`, { previousRef:
|
|
44
|
+
console.error(`"refId" not found: ${nextRefId}`, { previousRef: ref, previousRefId: this.currentRefId });
|
|
45
45
|
console.warn("Please report this to the developers. All refIds =>");
|
|
46
46
|
console.warn(Schema_1.Schema.debugRefIdsDecoder(this));
|
|
47
47
|
this.skipCurrentStructure(bytes, it, totalBytes);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Decoder.js","sourceRoot":"","sources":["../../src/decoder/Decoder.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AACnD,8CAAgF;AAChF,sCAAmC;AAEnC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,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,IAAI,IAAI,WAAW,CAAC;IAC/B,CAAC;IAED,oBAAoB,CAAE,IAAmB;QACrC,8CAA8C;QAE9C,6BAA6B;QAC7B,sDAAsD;QAEtD,mBAAmB;QACnB,OAAO,IAAK,IAAY,EAAE,CAAC;IAC/B,CAAC;IAED,eAAe,CAAC,GAAe,EAAE,UAAwB;QACrD,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAU,CAAC,CAAC,KAAK,QAAQ,CAAC;QAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAU,CAAC,CAAC;QAE/C,GAAG,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,GAAQ,EAAE,EAAE;YACjC,UAAU,CAAC,IAAI,CAAC;gBACZ,GAAG,EAAE,GAAU;gBACf,KAAK;gBACL,EAAE,EAAE,gBAAS,CAAC,MAAM;gBACpB,KAAK,EAAE,GAAG;gBACV,KAAK,EAAE,SAAS;gBAChB,aAAa,EAAE,KAAK;aACvB,CAAC,CAAC;YAEH,IAAI,aAAa,EAAE,CAAC;gBAChB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YACrD,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CAEJ;AAtJD,0BAsJC","sourcesContent":["import { TypeContext } from \"../types/TypeContext\";\nimport { $changes, $childType, $decoder, $onDecodeEnd } from \"../types/symbols\";\nimport { Schema } from \"../Schema\";\n\nimport { decode } from \"../encoding/decode\";\nimport { OPERATION, SWITCH_TO_STRUCTURE, TYPE_ID } from '../encoding/spec';\nimport type { Ref } from \"../encoder/ChangeTree\";\nimport type { Iterator } from \"../encoding/decode\";\nimport { ReferenceTracker } from \"./ReferenceTracker\";\nimport { DEFINITION_MISMATCH, type DataChange, type DecodeOperation } from \"./DecodeOperation\";\nimport { Collection } from \"../types/HelperTypes\";\n\nexport class Decoder<T extends Schema = any> {\n context: TypeContext;\n\n state: T;\n root: ReferenceTracker;\n\n currentRefId: number = 0;\n\n triggerChanges?: (allChanges: DataChange[]) => void;\n\n constructor(root: T, context?: TypeContext) {\n this.setState(root);\n\n this.context = context || new TypeContext(root.constructor as typeof Schema);\n\n // console.log(\">>>>>>>>>>>>>>>> Decoder types\");\n // this.context.schemas.forEach((id, schema) => {\n // console.log(\"type:\", id, schema.name, Object.keys(schema[Symbol.metadata]));\n // });\n }\n\n protected setState(root: T) {\n this.state = root;\n this.root = new ReferenceTracker();\n this.root.addRef(0, root);\n }\n\n decode(\n bytes: Buffer,\n it: Iterator = { offset: 0 },\n ref: Ref = this.state,\n ) {\n const allChanges: DataChange[] = [];\n\n const $root = this.root;\n const totalBytes = bytes.byteLength;\n\n let decoder: DecodeOperation = ref['constructor'][$decoder];\n\n this.currentRefId = 0;\n\n while (it.offset < totalBytes) {\n //\n // Peek ahead, check if it's a switch to a different structure\n //\n if (bytes[it.offset] == SWITCH_TO_STRUCTURE) {\n it.offset++;\n\n const nextRefId = decode.number(bytes, it);\n const nextRef = $root.refs.get(nextRefId);\n\n //\n // Trying to access a reference that haven't been decoded yet.\n //\n if (!nextRef) {\n console.error(`\"refId\" not found: ${nextRefId}`, { previousRef: ref, previousRefId: this.currentRefId });\n console.warn(\"Please report this to the developers. All refIds =>\");\n console.warn(Schema.debugRefIdsDecoder(this));\n this.skipCurrentStructure(bytes, it, totalBytes);\n }\n ref[$onDecodeEnd]?.()\n\n this.currentRefId = nextRefId;\n\n ref = nextRef;\n decoder = ref.constructor[$decoder];\n\n continue;\n }\n\n const result = decoder(this, bytes, it, ref, allChanges);\n\n if (result === DEFINITION_MISMATCH) {\n console.warn(\"@colyseus/schema: definition mismatch\");\n this.skipCurrentStructure(bytes, it, totalBytes);\n continue;\n }\n }\n\n // FIXME: DRY with SWITCH_TO_STRUCTURE block.\n ref[$onDecodeEnd]?.()\n\n // trigger changes\n this.triggerChanges?.(allChanges);\n\n // drop references of unused schemas\n $root.garbageCollectDeletedRefs();\n\n return allChanges;\n }\n\n skipCurrentStructure(bytes: Buffer, it: Iterator, totalBytes: number) {\n //\n // keep skipping next bytes until reaches a known structure\n // by local decoder.\n //\n const nextIterator: Iterator = { offset: it.offset };\n while (it.offset < totalBytes) {\n if (bytes[it.offset] === SWITCH_TO_STRUCTURE) {\n nextIterator.offset = it.offset + 1;\n if (this.root.refs.has(decode.number(bytes, nextIterator))) {\n break;\n }\n }\n it.offset++;\n }\n }\n\n getInstanceType(bytes: Buffer, it: Iterator, defaultType: typeof Schema): typeof Schema {\n let type: typeof Schema;\n\n if (bytes[it.offset] === TYPE_ID) {\n it.offset++;\n const type_id = decode.number(bytes, it);\n type = this.context.get(type_id);\n }\n\n return type || defaultType;\n }\n\n createInstanceOfType (type: typeof Schema): Schema {\n // let instance: Schema = new (type as any)();\n\n // // assign root on $changes\n // instance[$changes].root = this.root[$changes].root;\n\n // return instance;\n return new (type as any)();\n }\n\n removeChildRefs(ref: Collection, allChanges: DataChange[]) {\n const needRemoveRef = typeof (ref[$childType]) !== \"string\";\n const refId = this.root.refIds.get(ref as Ref);\n\n ref.forEach((value: any, key: any) => {\n allChanges.push({\n ref: ref as Ref,\n refId,\n op: OPERATION.DELETE,\n field: key,\n value: undefined,\n previousValue: value\n });\n\n if (needRemoveRef) {\n this.root.removeRef(this.root.refIds.get(value));\n }\n });\n }\n\n}\n\n"]}
|
package/package.json
CHANGED
package/src/decoder/Decoder.ts
CHANGED
|
@@ -65,7 +65,7 @@ export class Decoder<T extends Schema = any> {
|
|
|
65
65
|
// Trying to access a reference that haven't been decoded yet.
|
|
66
66
|
//
|
|
67
67
|
if (!nextRef) {
|
|
68
|
-
console.error(`"refId" not found: ${nextRefId}`, { previousRef:
|
|
68
|
+
console.error(`"refId" not found: ${nextRefId}`, { previousRef: ref, previousRefId: this.currentRefId });
|
|
69
69
|
console.warn("Please report this to the developers. All refIds =>");
|
|
70
70
|
console.warn(Schema.debugRefIdsDecoder(this));
|
|
71
71
|
this.skipCurrentStructure(bytes, it, totalBytes);
|