How to use the @msgpack/msgpack.decode 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 vladimiry / ElectronMail / src / electron-main / database / serialization.ts View on Github external
this.read = async (data: Buffer) => {
            this.logger.info(`read() buffer.length: ${data.length}`);

            const {header: {serialization}} = persistencePartsUtil.split(data);
            const decryptedData = await encryptionAdapter.read(data);

            if (serialization && serialization.type === "msgpack") {
                this.logger.verbose(`"msgpack.decode" start`);
                const decoded = msgpack.decode(decryptedData) as FsDb;
                this.logger.verbose(`"msgpack.decode" end`);
                return decoded;
            }

            const readableStream = bufferToStream(decryptedData);

            return new Promise((resolve, reject) => {
                this.logger.verbose(`"oboe" start`);

                // TODO replace "oboe" with alternative library that doesn't block the Event Loop so heavily
                //      review the following libraries:
                //      - https://gitlab.com/philbooth/bfj
                //      - https://github.com/ibmruntimes/yieldable-json
                //      or consider moving parsing to a separate Worker/Process
                oboe(readableStream)
                    .done((parsed) => {
github nickvdyck / webtty / src / WebTty.UI / application / services / TerminalManager.ts View on Github external
public async *messages(): AsyncIterableIterator<
        OpenNewTabReply | StdOutMessage
    > {
        for await (const data of this.connection) {
            if (!data) continue
            // TODO: maybe throw an error??
            if (typeof data === "string") continue

            const messages = BinaryMessageFormat.parse(data)

            for (const message of messages) {
                const decoded = decode(message) as [string, Buffer]
                const type = decoded[0]
                const payload = decode(decoded[1])

                switch (type) {
                    case "OpenNewTabReply":
                        yield OpenNewTabReply.fromJS(payload)
                        break

                    case "StdOutMessage": {
                        const stdOut = StdOutMessage.fromJS(payload)
                        stdOut.data = Array.from(
                            (payload as { Data: number[] })["Data"],
                        )
                        yield stdOut
                        break
                    }
github nickvdyck / webtty / src / WebTty.UI / application / services / TerminalManager.ts View on Github external
public async *messages(): AsyncIterableIterator<
        OpenNewTabReply | StdOutMessage
    > {
        for await (const data of this.connection) {
            if (!data) continue
            // TODO: maybe throw an error??
            if (typeof data === "string") continue

            const messages = BinaryMessageFormat.parse(data)

            for (const message of messages) {
                const decoded = decode(message) as [string, Buffer]
                const type = decoded[0]
                const payload = decode(decoded[1])

                switch (type) {
                    case "OpenNewTabReply":
                        yield OpenNewTabReply.fromJS(payload)
                        break

                    case "StdOutMessage": {
                        const stdOut = StdOutMessage.fromJS(payload)
                        stdOut.data = Array.from(
                            (payload as { Data: number[] })["Data"],
                        )
                        yield stdOut
                        break
                    }

                    default:
github pioneers / PieCentral / runtime / runtime-node-client / runtime-client.js View on Github external
async _recv(name) {
    for await (const [packet] of this.sockets[name]) {
      this.bytes_recv += packet.length;
      return msgpack.decode(packet);
    }
  }
github BitbossIO / keyring / packages / msgpack-plugin / lib / transaction.js View on Github external
tx.data().forEach((datum) => {
          if(
            datum
            && datum[0].toString() === '19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut'
            && datum[2].toString() == 'application/msgpack'
          ) {
            try {
              results.push(msgpack.decode(datum[1]));
            } catch (err) {}
          }
        });
        return results;
github nickvdyck / webtty / src / WebTty.Hosting / Client / features / terminal / protocol / deserializeMessages.ts View on Github external
const deserializeMessage = (buffer: Uint8Array): Messages => {
    const [type, payload] = decode(buffer) as [string, unknown]
    switch (type) {
        case "OpenNewTabReply": {
            return OpenNewTabReply.fromJS(payload)
        }

        case "OutputEvent": {
            const message = OutputEvent.fromJS(payload)
            message.data = Array.from((payload as { Data: number[] })["Data"])
            return message
        }

        default:
            return new UnknownMessage(type, payload)
    }
}

@msgpack/msgpack

MessagePack for ECMA-262/JavaScript/TypeScript

ISC
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis