Skip to content

[Bug]: encode test outdated? #205

Open
@YuriArthas

Description

@YuriArthas

Bug description

My @colyseus/schema version: 3.0.42, install by npm, running in cocos creator 3.8.6

// schema\test\Schema.test.ts:293

        it("bigints", () => {
            class Data extends Schema {
                @type("biguint64") u64: bigint;
                @type("bigint64") i64: bigint;
            }

            const buint = BigInt(Number.MAX_SAFE_INTEGER) + 10000n;
            const bint = BigInt(Number.MIN_SAFE_INTEGER) - 10000n;

            let data = new Data();
            data.u64 = buint;
            data.i64 = bint;

            let encoded = data.encode();

            const decoded = new Data();
            decoded.decode(encoded);

            assert.strictEqual(decoded.u64, buint);
            assert.strictEqual(decoded.i64, bint);
        });

Is this sample code outdated?
It seems like it doesn't compile in TypeScript anymore.



class TestSchema extends Schema {
    @type("string")
    special: string; 

    @type("string", { manual: false })
    name: string; 
}

        const testInstance = new TestSchema();
        const encoder = new Encoder(testInstance);
        encoder.discardChanges();

        testInstance.special = "special";
        testInstance.name = "name";

        const bytes1 = encoder.encodeAll();
        console.log(bytes1);  // 0 byte!

        testInstance.setDirty("name");  

        // testInstance.name = "name2";
        const bytes2 = encoder.encodeAll();
        console.log(bytes2);  // 6 bytes

        const client_schema = new TestSchema();

        const decoder = new Decoder(client_schema); 
        decoder.decode(bytes2);
        console.log(client_schema);  // just has name, no "special"

The second issue is that you must call setDirty() for the fields to sync correctly. For example, name can be synced, but special cannot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions