var errorParser, infoParser, parser;

parser = function(buffer, options) {
  var class_, length, lineNumber, message, number, procName, serverName, state, token;
  length = buffer.readUInt16LE();
  number = buffer.readUInt32LE();
  state = buffer.readUInt8();
  class_ = buffer.readUInt8();
  message = buffer.readUsVarchar();
  serverName = buffer.readBVarchar();
  procName = buffer.readBVarchar();
  if (options.tdsVersion < '7_2') {
    lineNumber = buffer.readUInt16LE();
  } else {
    lineNumber = buffer.readUInt32LE();
  }
  return token = {
    number: number,
    state: state,
    "class": class_,
    message: message,
    serverName: serverName,
    procName: procName,
    lineNumber: lineNumber
  };
};

infoParser = function(buffer, colMetadata, options) {
  var token;
  token = parser(buffer, options);
  token.name = 'INFO';
  token.event = 'infoMessage';
  return token;
};

errorParser = function(buffer, colMetadata, options) {
  var token;
  token = parser(buffer, options);
  token.name = 'ERROR';
  token.event = 'errorMessage';
  return token;
};

exports.infoParser = infoParser;

exports.errorParser = errorParser;
