artilleryio / artillery-core

artillery-core - deprecated
Mozilla Public License 2.0
29 stars 104 forks source link

Send binary packet through WS? #189

Open Cristy94 opened 7 years ago

Cristy94 commented 7 years ago

I want to integrate artillery-core with a WS application that uses Protobuf for encoding the messages. Is it possible to send binary data through the WS using artillery?

Cristy94 commented 7 years ago

Currently to fix this I save the packect in userContex.vars as a hex string.

Also, in the engine_ws.js I added this check:

    if (payload === undefined) {
        debug("Error: Payload is undefined.");
        return callback(null, context);
    }

And updated this convert it from the hex string to an Uint8Array


    if (typeof payload === 'object') {
      payload = JSON.stringify(payload);
    } else {
      // if(payload) payload = payload.toString();
      // Convert string payload to buffer
      if(payload) {
          var bytes = new Uint8Array(Math.ceil(payload.length / 2));
          for (var i = 0; i < bytes.length; i++) bytes[i] = parseInt(payload.substr(i * 2, 2), 16);
      }
    }

Then just send the bytes array.

Probably there could be a binary options that does this conversion, as I didn't seem to find a way to save binary variables in userContext.vars