auth_switch_response.js 707 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. // http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchRequest
  3. const Packet = require('../packets/packet');
  4. class AuthSwitchResponse {
  5. constructor(data) {
  6. if (!Buffer.isBuffer(data)) {
  7. data = Buffer.from(data);
  8. }
  9. this.data = data;
  10. }
  11. toPacket() {
  12. const length = 4 + this.data.length;
  13. const buffer = Buffer.allocUnsafe(length);
  14. const packet = new Packet(0, buffer, 0, length);
  15. packet.offset = 4;
  16. packet.writeBuffer(this.data);
  17. return packet;
  18. }
  19. static fromPacket(packet) {
  20. const data = packet.readBuffer();
  21. return new AuthSwitchResponse(data);
  22. }
  23. }
  24. module.exports = AuthSwitchResponse;