(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(["exports", "@aws-sdk/util-utf8-node", "@aws-sdk/eventstream-marshaller"], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require("@aws-sdk/util-utf8-node"), require("@aws-sdk/eventstream-marshaller"));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.utilUtf8Node, global.eventstreamMarshaller);
    global.decodeAWSMessage = mod.exports;
  }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _utilUtf8Node, _eventstreamMarshaller) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.default = void 0;

  const decodeMessage = function decodeMessage({
    message,
    _marshaller = new _eventstreamMarshaller.EventStreamMarshaller(_utilUtf8Node.toUtf8, _utilUtf8Node.fromUtf8)
  }) {
    const messageWrapper = _marshaller.unmarshall(Buffer.from(message));

    const messageBody = JSON.parse(String.fromCharCode.apply(String, messageWrapper.body));

    if (messageWrapper.headers[':message-type'].value === 'event') {
      return messageBody;
    }

    throw new Error(messageBody.Message);
  };

  var _default = decodeMessage;
  _exports.default = _default;
});
//# sourceMappingURL=decodeAWSMessage.js.map