"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.errorParser = errorParser;
exports.infoParser = infoParser;
var _helpers = require("./helpers");
var _token = require("./token");
function readToken(buf, offset, options) {
  let tokenLength;
  ({
    offset,
    value: tokenLength
  } = (0, _helpers.readUInt16LE)(buf, offset));
  if (buf.length < tokenLength + offset) {
    throw new _helpers.NotEnoughDataError(tokenLength + offset);
  }
  let number;
  ({
    offset,
    value: number
  } = (0, _helpers.readUInt32LE)(buf, offset));
  let state;
  ({
    offset,
    value: state
  } = (0, _helpers.readUInt8)(buf, offset));
  let clazz;
  ({
    offset,
    value: clazz
  } = (0, _helpers.readUInt8)(buf, offset));
  let message;
  ({
    offset,
    value: message
  } = (0, _helpers.readUsVarChar)(buf, offset));
  let serverName;
  ({
    offset,
    value: serverName
  } = (0, _helpers.readBVarChar)(buf, offset));
  let procName;
  ({
    offset,
    value: procName
  } = (0, _helpers.readBVarChar)(buf, offset));
  let lineNumber;
  ({
    offset,
    value: lineNumber
  } = options.tdsVersion < '7_2' ? (0, _helpers.readUInt16LE)(buf, offset) : (0, _helpers.readUInt32LE)(buf, offset));
  return new _helpers.Result({
    'number': number,
    'state': state,
    'class': clazz,
    'message': message,
    'serverName': serverName,
    'procName': procName,
    'lineNumber': lineNumber
  }, offset);
}
function infoParser(buf, offset, options) {
  let data;
  ({
    offset,
    value: data
  } = readToken(buf, offset, options));
  return new _helpers.Result(new _token.InfoMessageToken(data), offset);
}
function errorParser(buf, offset, options) {
  let data;
  ({
    offset,
    value: data
  } = readToken(buf, offset, options));
  return new _helpers.Result(new _token.ErrorMessageToken(data), offset);
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5916 characters]