How to use the @msgpack/msgpack.encode function in @msgpack/msgpack

To help you get started, we’ve selected a few @msgpack/msgpack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github colyseus / schema / benchmark / FossilDeltaComparison.ts View on Github external
let msgpackState = { players: {} };

const fixedUnitId = nanoid(9);

for (let i=0; i<100; i++) {
  const id = (i === 50) ? fixedUnitId : nanoid(9);
  const name = "Player " + i;
  const x = Math.floor(Math.random() * 200);
  const y = Math.floor(Math.random() * 200);
  state.players[ id ] = new Player(name, x, y);
  msgpackState.players[id] = { name, x, y };
}

const firstStateEncoded = msgpack.encode(msgpackState);
let encoded = state.encode();

const decodedState = new State();
decodedState.decode(encoded);

console.log("(@colyseus/state) INITIAL STATE SIZE:", encoded.length);
console.log("(msgpack) INITIAL STATE SIZE:", firstStateEncoded.length);
console.log("");

{
  // CHANGE X/Y OF A SINGLE ENTITY
  const x = Math.floor(Math.random() * 200);
  const y = Math.floor(Math.random() * 200);
  state.players[fixedUnitId].x = x
  state.players[fixedUnitId].y = y
  msgpackState.players[fixedUnitId].x = x
github colyseus / schema / benchmark / FossilDeltaComparison.ts View on Github external
//   for (let id in msgpackState.players) {
//     const x = Math.floor(Math.random() * 200);
//     const y = Math.floor(Math.random() * 200);
//     state.players[id].x = x
//     state.players[id].y = y
//     msgpackState.players[id].x = x
//     msgpackState.players[id].y = y
//     i++;
//   }
// }

encoded = state.encode();
decodedState.decode(encoded);

console.log("(@colyseus/state) SUBSEQUENT PATCH:", encoded.length);
console.log("(msgpack) SUBSEQUENT PATCH:", fossildelta.create(firstStateEncoded, msgpack.encode(msgpackState)).length);
github nickvdyck / webtty / src / WebTty.UI / application / services / TerminalManager.ts View on Github external
const serializeCommand = (message: Messages): ArrayBuffer => {
    const bytes = encode(message.toJSON())
    const payload = encode([getName(message), bytes]).slice()
    const data = BinaryMessageFormat.write(payload)
    return data
}
github nickvdyck / webtty / src / WebTty.UI / application / services / TerminalManager.ts View on Github external
const serializeCommand = (message: Messages): ArrayBuffer => {
    const bytes = encode(message.toJSON())
    const payload = encode([getName(message), bytes]).slice()
    const data = BinaryMessageFormat.write(payload)
    return data
}
github neovim / node-client / packages / neovim / src / utils / transport.ts View on Github external
private encodeToBuffer(value: unknown) {
    const encoded = encode(value, { extensionCodec: this.extensionCodec });
    return Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);
  }
github neovim / node-client / packages / neovim / src / utils / transport.ts View on Github external
send(resp: any, isError?: boolean): void {
    if (this.sent) {
      throw new Error(`Response to id ${this.requestId} already sent`);
    }

    const encoded = encode([
      1,
      this.requestId,
      isError ? resp : null,
      !isError ? resp : null,
    ]);

    this.encoder.write(
      Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength)
    );
    this.sent = true;
  }
}
github pioneers / PieCentral / runtime / runtime-node-client / runtime-client.js View on Github external
async _send(name, payload) {
    let packet = msgpack.encode(payload);
    this.bytes_sent += packet.length;
    let socket = this.sockets[name];
    if (this.socketConfigs[name].type === Radio) {
      return await socket.send(packet, { group: '' });
    }
    return await socket.send(packet);
  }
github vladimiry / ElectronMail / src / electron-main / database / index.spec.ts View on Github external
const {options, fileFs} = buildDatabase();
    const db = new databaseModule.Database(options, fileFs);

    const folderStub = buildFolder();
    db.initAccount({type: "protonmail", login: "login1"})
        .folders[folderStub.pk] = await validateEntity("folders", folderStub, "protonmail");

    t.false(encryptionAdapterWriteSpy.called);

    await db.saveToFile();
    const dump = JSON.parse(JSON.stringify(db.readonlyDbInstance()));

    t.is(1, encryptionAdapterWriteSpy.callCount);
    t.deepEqual(
        Buffer.from(
            msgpack.encode(dump),
        ),
        encryptionAdapterWriteSpy.getCall(0).args[0],
    );
});

@msgpack/msgpack

MessagePack for ECMA-262/JavaScript/TypeScript

ISC
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis