"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _helpers = require("./helpers");
var _token = require("./token");
const FEATURE_ID = {
  SESSIONRECOVERY: 0x01,
  FEDAUTH: 0x02,
  COLUMNENCRYPTION: 0x04,
  GLOBALTRANSACTIONS: 0x05,
  AZURESQLSUPPORT: 0x08,
  UTF8_SUPPORT: 0x0A,
  TERMINATOR: 0xFF
};
function featureExtAckParser(buf, offset, _options) {
  let fedAuth;
  let utf8Support;
  while (true) {
    let featureId;
    ({
      value: featureId,
      offset
    } = (0, _helpers.readUInt8)(buf, offset));
    if (featureId === FEATURE_ID.TERMINATOR) {
      return new _helpers.Result(new _token.FeatureExtAckToken(fedAuth, utf8Support), offset);
    }
    let featureAckDataLen;
    ({
      value: featureAckDataLen,
      offset
    } = (0, _helpers.readUInt32LE)(buf, offset));
    if (buf.length < offset + featureAckDataLen) {
      throw new _helpers.NotEnoughDataError(offset + featureAckDataLen);
    }
    const featureData = buf.slice(offset, offset + featureAckDataLen);
    offset += featureAckDataLen;
    switch (featureId) {
      case FEATURE_ID.FEDAUTH:
        fedAuth = featureData;
        break;
      case FEATURE_ID.UTF8_SUPPORT:
        utf8Support = !!featureData[0];
        break;
    }
  }
}
var _default = exports.default = featureExtAckParser;
module.exports = featureExtAckParser;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4228 characters]