text: import { __assign, __awaiter, __generator, __values } from "tslib";
  import { HttpRequest as __HttpRequest } from "@aws-sdk/protocol-http";
  import { dateToUtcString as __dateToUtcString, extendedEncodeURIComponent as __extendedEncodeURIComponent } from "@aws-sdk/smithy-client";
  import { XmlNode as __XmlNode, XmlText as __XmlText } from "@aws-sdk/xml-builder";
  import { parse as xmlParse } from "fast-xml-parser";
  export function serializeAws_restXmlAbortMultipartUploadCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "x-id": "AbortMultipartUpload"
              };
              if (input.UploadId !== undefined) {
                  query["uploadId"] = input.UploadId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlCompleteMultipartUploadCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {};
              if (input.UploadId !== undefined) {
                  query["uploadId"] = input.UploadId;
              }
              if (input.MultipartUpload !== undefined) {
                  contents = serializeAws_restXmlCompletedMultipartUpload(input.MultipartUpload, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "POST", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlCopyObjectCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.ACL !== undefined) {
                  headers["x-amz-acl"] = input.ACL;
              }
              if (input.CacheControl !== undefined) {
                  headers["Cache-Control"] = input.CacheControl;
              }
              if (input.ContentDisposition !== undefined) {
                  headers["Content-Disposition"] = input.ContentDisposition;
              }
              if (input.ContentEncoding !== undefined) {
                  headers["Content-Encoding"] = input.ContentEncoding;
              }
              if (input.ContentLanguage !== undefined) {
                  headers["Content-Language"] = input.ContentLanguage;
              }
              if (input.ContentType !== undefined) {
                  headers["Content-Type"] = input.ContentType;
              }
              if (input.CopySource !== undefined) {
                  headers["x-amz-copy-source"] = input.CopySource;
              }
              if (input.CopySourceIfMatch !== undefined) {
                  headers["x-amz-copy-source-if-match"] = input.CopySourceIfMatch;
              }
              if (input.CopySourceIfModifiedSince !== undefined) {
                  headers["x-amz-copy-source-if-modified-since"] = __dateToUtcString(input.CopySourceIfModifiedSince).toString();
              }
              if (input.CopySourceIfNoneMatch !== undefined) {
                  headers["x-amz-copy-source-if-none-match"] = input.CopySourceIfNoneMatch;
              }
              if (input.CopySourceIfUnmodifiedSince !== undefined) {
                  headers["x-amz-copy-source-if-unmodified-since"] = __dateToUtcString(input.CopySourceIfUnmodifiedSince).toString();
              }
              if (input.CopySourceSSECustomerAlgorithm !== undefined) {
                  headers["x-amz-copy-source-server-side-encryption-customer-algorithm"] =
                      input.CopySourceSSECustomerAlgorithm;
              }
              if (input.CopySourceSSECustomerKey !== undefined) {
                  headers["x-amz-copy-source-server-side-encryption-customer-key"] =
                      input.CopySourceSSECustomerKey;
              }
              if (input.CopySourceSSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-copy-source-server-side-encryption-customer-key-MD5"] =
                      input.CopySourceSSECustomerKeyMD5;
              }
              if (input.Expires !== undefined) {
                  headers["Expires"] = __dateToUtcString(input.Expires).toString();
              }
              if (input.GrantFullControl !== undefined) {
                  headers["x-amz-grant-full-control"] = input.GrantFullControl;
              }
              if (input.GrantRead !== undefined) {
                  headers["x-amz-grant-read"] = input.GrantRead;
              }
              if (input.GrantReadACP !== undefined) {
                  headers["x-amz-grant-read-acp"] = input.GrantReadACP;
              }
              if (input.GrantWriteACP !== undefined) {
                  headers["x-amz-grant-write-acp"] = input.GrantWriteACP;
              }
              if (input.MetadataDirective !== undefined) {
                  headers["x-amz-metadata-directive"] = input.MetadataDirective;
              }
              if (input.ObjectLockLegalHoldStatus !== undefined) {
                  headers["x-amz-object-lock-legal-hold"] = input.ObjectLockLegalHoldStatus;
              }
              if (input.ObjectLockMode !== undefined) {
                  headers["x-amz-object-lock-mode"] = input.ObjectLockMode;
              }
              if (input.ObjectLockRetainUntilDate !== undefined) {
                  headers["x-amz-object-lock-retain-until-date"] = (input.ObjectLockRetainUntilDate.toISOString().split(".")[0] + "Z").toString();
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              if (input.SSECustomerAlgorithm !== undefined) {
                  headers["x-amz-server-side-encryption-customer-algorithm"] =
                      input.SSECustomerAlgorithm;
              }
              if (input.SSECustomerKey !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key"] = input.SSECustomerKey;
              }
              if (input.SSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key-MD5"] =
                      input.SSECustomerKeyMD5;
              }
              if (input.SSEKMSEncryptionContext !== undefined) {
                  headers["x-amz-server-side-encryption-context"] =
                      input.SSEKMSEncryptionContext;
              }
              if (input.SSEKMSKeyId !== undefined) {
                  headers["x-amz-server-side-encryption-aws-kms-key-id"] = input.SSEKMSKeyId;
              }
              if (input.ServerSideEncryption !== undefined) {
                  headers["x-amz-server-side-encryption"] = input.ServerSideEncryption;
              }
              if (input.StorageClass !== undefined) {
                  headers["x-amz-storage-class"] = input.StorageClass;
              }
              if (input.Tagging !== undefined) {
                  headers["x-amz-tagging"] = input.Tagging;
              }
              if (input.TaggingDirective !== undefined) {
                  headers["x-amz-tagging-directive"] = input.TaggingDirective;
              }
              if (input.WebsiteRedirectLocation !== undefined) {
                  headers["x-amz-website-redirect-location"] = input.WebsiteRedirectLocation;
              }
              if (input.Metadata !== undefined) {
                  Object.keys(input.Metadata).forEach(function (suffix) {
                      headers["x-amz-meta-" + suffix] = input.Metadata[suffix];
                  });
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "x-id": "CopyObject"
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlCreateBucketCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ACL !== undefined) {
                  headers["x-amz-acl"] = input.ACL;
              }
              if (input.GrantFullControl !== undefined) {
                  headers["x-amz-grant-full-control"] = input.GrantFullControl;
              }
              if (input.GrantRead !== undefined) {
                  headers["x-amz-grant-read"] = input.GrantRead;
              }
              if (input.GrantReadACP !== undefined) {
                  headers["x-amz-grant-read-acp"] = input.GrantReadACP;
              }
              if (input.GrantWrite !== undefined) {
                  headers["x-amz-grant-write"] = input.GrantWrite;
              }
              if (input.GrantWriteACP !== undefined) {
                  headers["x-amz-grant-write-acp"] = input.GrantWriteACP;
              }
              if (input.ObjectLockEnabledForBucket !== undefined) {
                  headers["x-amz-bucket-object-lock-enabled"] = input.ObjectLockEnabledForBucket.toString();
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.CreateBucketConfiguration !== undefined) {
                  contents = serializeAws_restXmlCreateBucketConfiguration(input.CreateBucketConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlCreateMultipartUploadCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.ACL !== undefined) {
                  headers["x-amz-acl"] = input.ACL;
              }
              if (input.CacheControl !== undefined) {
                  headers["Cache-Control"] = input.CacheControl;
              }
              if (input.ContentDisposition !== undefined) {
                  headers["Content-Disposition"] = input.ContentDisposition;
              }
              if (input.ContentEncoding !== undefined) {
                  headers["Content-Encoding"] = input.ContentEncoding;
              }
              if (input.ContentLanguage !== undefined) {
                  headers["Content-Language"] = input.ContentLanguage;
              }
              if (input.ContentType !== undefined) {
                  headers["Content-Type"] = input.ContentType;
              }
              if (input.Expires !== undefined) {
                  headers["Expires"] = __dateToUtcString(input.Expires).toString();
              }
              if (input.GrantFullControl !== undefined) {
                  headers["x-amz-grant-full-control"] = input.GrantFullControl;
              }
              if (input.GrantRead !== undefined) {
                  headers["x-amz-grant-read"] = input.GrantRead;
              }
              if (input.GrantReadACP !== undefined) {
                  headers["x-amz-grant-read-acp"] = input.GrantReadACP;
              }
              if (input.GrantWriteACP !== undefined) {
                  headers["x-amz-grant-write-acp"] = input.GrantWriteACP;
              }
              if (input.ObjectLockLegalHoldStatus !== undefined) {
                  headers["x-amz-object-lock-legal-hold"] = input.ObjectLockLegalHoldStatus;
              }
              if (input.ObjectLockMode !== undefined) {
                  headers["x-amz-object-lock-mode"] = input.ObjectLockMode;
              }
              if (input.ObjectLockRetainUntilDate !== undefined) {
                  headers["x-amz-object-lock-retain-until-date"] = (input.ObjectLockRetainUntilDate.toISOString().split(".")[0] + "Z").toString();
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              if (input.SSECustomerAlgorithm !== undefined) {
                  headers["x-amz-server-side-encryption-customer-algorithm"] =
                      input.SSECustomerAlgorithm;
              }
              if (input.SSECustomerKey !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key"] = input.SSECustomerKey;
              }
              if (input.SSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key-MD5"] =
                      input.SSECustomerKeyMD5;
              }
              if (input.SSEKMSEncryptionContext !== undefined) {
                  headers["x-amz-server-side-encryption-context"] =
                      input.SSEKMSEncryptionContext;
              }
              if (input.SSEKMSKeyId !== undefined) {
                  headers["x-amz-server-side-encryption-aws-kms-key-id"] = input.SSEKMSKeyId;
              }
              if (input.ServerSideEncryption !== undefined) {
                  headers["x-amz-server-side-encryption"] = input.ServerSideEncryption;
              }
              if (input.StorageClass !== undefined) {
                  headers["x-amz-storage-class"] = input.StorageClass;
              }
              if (input.Tagging !== undefined) {
                  headers["x-amz-tagging"] = input.Tagging;
              }
              if (input.WebsiteRedirectLocation !== undefined) {
                  headers["x-amz-website-redirect-location"] = input.WebsiteRedirectLocation;
              }
              if (input.Metadata !== undefined) {
                  Object.keys(input.Metadata).forEach(function (suffix) {
                      headers["x-amz-meta-" + suffix] = input.Metadata[suffix];
                  });
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  uploads: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "POST", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketAnalyticsConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  analytics: ""
              };
              if (input.Id !== undefined) {
                  query["id"] = input.Id;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketCorsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  cors: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketEncryptionCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  encryption: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketInventoryConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  inventory: ""
              };
              if (input.Id !== undefined) {
                  query["id"] = input.Id;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketLifecycleCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  lifecycle: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketMetricsConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  metrics: ""
              };
              if (input.Id !== undefined) {
                  query["id"] = input.Id;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketPolicyCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  policy: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketReplicationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  replication: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketTaggingCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  tagging: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteBucketWebsiteCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  website: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteObjectCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.BypassGovernanceRetention !== undefined) {
                  headers["x-amz-bypass-governance-retention"] = input.BypassGovernanceRetention.toString();
              }
              if (input.MFA !== undefined) {
                  headers["x-amz-mfa"] = input.MFA;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "x-id": "DeleteObject"
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteObjectTaggingCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  tagging: ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeleteObjectsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.BypassGovernanceRetention !== undefined) {
                  headers["x-amz-bypass-governance-retention"] = input.BypassGovernanceRetention.toString();
              }
              if (input.MFA !== undefined) {
                  headers["x-amz-mfa"] = input.MFA;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  delete: ""
              };
              if (input.Delete !== undefined) {
                  contents = serializeAws_restXmlDelete(input.Delete, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "POST", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlDeletePublicAccessBlockCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  publicAccessBlock: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "DELETE", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketAccelerateConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  accelerate: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketAclCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  acl: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketAnalyticsConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  analytics: "",
                  "x-id": "GetBucketAnalyticsConfiguration"
              };
              if (input.Id !== undefined) {
                  query["id"] = input.Id;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketCorsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  cors: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketEncryptionCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  encryption: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketInventoryConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  inventory: "",
                  "x-id": "GetBucketInventoryConfiguration"
              };
              if (input.Id !== undefined) {
                  query["id"] = input.Id;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketLifecycleConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  lifecycle: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketLocationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  location: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketLoggingCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  logging: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketMetricsConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  metrics: "",
                  "x-id": "GetBucketMetricsConfiguration"
              };
              if (input.Id !== undefined) {
                  query["id"] = input.Id;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketNotificationConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  notification: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketPolicyCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  policy: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketPolicyStatusCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  policyStatus: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketReplicationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  replication: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketRequestPaymentCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  requestPayment: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketTaggingCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  tagging: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketVersioningCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  versioning: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetBucketWebsiteCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  website: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetObjectCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.IfMatch !== undefined) {
                  headers["If-Match"] = input.IfMatch;
              }
              if (input.IfModifiedSince !== undefined) {
                  headers["If-Modified-Since"] = __dateToUtcString(input.IfModifiedSince).toString();
              }
              if (input.IfNoneMatch !== undefined) {
                  headers["If-None-Match"] = input.IfNoneMatch;
              }
              if (input.IfUnmodifiedSince !== undefined) {
                  headers["If-Unmodified-Since"] = __dateToUtcString(input.IfUnmodifiedSince).toString();
              }
              if (input.Range !== undefined) {
                  headers["Range"] = input.Range;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              if (input.SSECustomerAlgorithm !== undefined) {
                  headers["x-amz-server-side-encryption-customer-algorithm"] =
                      input.SSECustomerAlgorithm;
              }
              if (input.SSECustomerKey !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key"] = input.SSECustomerKey;
              }
              if (input.SSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key-MD5"] =
                      input.SSECustomerKeyMD5;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "x-id": "GetObject"
              };
              if (input.PartNumber !== undefined) {
                  query["partNumber"] = input.PartNumber.toString();
              }
              if (input.ResponseCacheControl !== undefined) {
                  query["response-cache-control"] = input.ResponseCacheControl;
              }
              if (input.ResponseContentDisposition !== undefined) {
                  query["response-content-disposition"] = input.ResponseContentDisposition;
              }
              if (input.ResponseContentEncoding !== undefined) {
                  query["response-content-encoding"] = input.ResponseContentEncoding;
              }
              if (input.ResponseContentLanguage !== undefined) {
                  query["response-content-language"] = input.ResponseContentLanguage;
              }
              if (input.ResponseContentType !== undefined) {
                  query["response-content-type"] = input.ResponseContentType;
              }
              if (input.ResponseExpires !== undefined) {
                  query["response-expires"] = (input.ResponseExpires.toISOString().split(".")[0] + "Z").toString();
              }
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetObjectAclCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  acl: ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetObjectLegalHoldCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "legal-hold": ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetObjectLockConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  "object-lock": ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetObjectRetentionCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  retention: ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetObjectTaggingCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  tagging: ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetObjectTorrentCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  torrent: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlGetPublicAccessBlockCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  publicAccessBlock: ""
              };
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlHeadBucketCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "HEAD", headers: headers, path: resolvedPath, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlHeadObjectCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.IfMatch !== undefined) {
                  headers["If-Match"] = input.IfMatch;
              }
              if (input.IfModifiedSince !== undefined) {
                  headers["If-Modified-Since"] = __dateToUtcString(input.IfModifiedSince).toString();
              }
              if (input.IfNoneMatch !== undefined) {
                  headers["If-None-Match"] = input.IfNoneMatch;
              }
              if (input.IfUnmodifiedSince !== undefined) {
                  headers["If-Unmodified-Since"] = __dateToUtcString(input.IfUnmodifiedSince).toString();
              }
              if (input.Range !== undefined) {
                  headers["Range"] = input.Range;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              if (input.SSECustomerAlgorithm !== undefined) {
                  headers["x-amz-server-side-encryption-customer-algorithm"] =
                      input.SSECustomerAlgorithm;
              }
              if (input.SSECustomerKey !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key"] = input.SSECustomerKey;
              }
              if (input.SSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key-MD5"] =
                      input.SSECustomerKeyMD5;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {};
              if (input.PartNumber !== undefined) {
                  query["partNumber"] = input.PartNumber.toString();
              }
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "HEAD", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlListBucketAnalyticsConfigurationsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  analytics: "",
                  "x-id": "ListBucketAnalyticsConfigurations"
              };
              if (input.ContinuationToken !== undefined) {
                  query["continuation-token"] = input.ContinuationToken;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlListBucketInventoryConfigurationsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  inventory: "",
                  "x-id": "ListBucketInventoryConfigurations"
              };
              if (input.ContinuationToken !== undefined) {
                  query["continuation-token"] = input.ContinuationToken;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlListBucketMetricsConfigurationsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  metrics: "",
                  "x-id": "ListBucketMetricsConfigurations"
              };
              if (input.ContinuationToken !== undefined) {
                  query["continuation-token"] = input.ContinuationToken;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlListBucketsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/";
              body = "";
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlListMultipartUploadsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  uploads: ""
              };
              if (input.Delimiter !== undefined) {
                  query["delimiter"] = input.Delimiter;
              }
              if (input.EncodingType !== undefined) {
                  query["encoding-type"] = input.EncodingType;
              }
              if (input.KeyMarker !== undefined) {
                  query["key-marker"] = input.KeyMarker;
              }
              if (input.MaxUploads !== undefined) {
                  query["max-uploads"] = input.MaxUploads.toString();
              }
              if (input.Prefix !== undefined) {
                  query["prefix"] = input.Prefix;
              }
              if (input.UploadIdMarker !== undefined) {
                  query["upload-id-marker"] = input.UploadIdMarker;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlListObjectVersionsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  versions: ""
              };
              if (input.Delimiter !== undefined) {
                  query["delimiter"] = input.Delimiter;
              }
              if (input.EncodingType !== undefined) {
                  query["encoding-type"] = input.EncodingType;
              }
              if (input.KeyMarker !== undefined) {
                  query["key-marker"] = input.KeyMarker;
              }
              if (input.MaxKeys !== undefined) {
                  query["max-keys"] = input.MaxKeys.toString();
              }
              if (input.Prefix !== undefined) {
                  query["prefix"] = input.Prefix;
              }
              if (input.VersionIdMarker !== undefined) {
                  query["version-id-marker"] = input.VersionIdMarker;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlListObjectsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {};
              if (input.Delimiter !== undefined) {
                  query["delimiter"] = input.Delimiter;
              }
              if (input.EncodingType !== undefined) {
                  query["encoding-type"] = input.EncodingType;
              }
              if (input.Marker !== undefined) {
                  query["marker"] = input.Marker;
              }
              if (input.MaxKeys !== undefined) {
                  query["max-keys"] = input.MaxKeys.toString();
              }
              if (input.Prefix !== undefined) {
                  query["prefix"] = input.Prefix;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlListObjectsV2Command(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  "list-type": "2"
              };
              if (input.ContinuationToken !== undefined) {
                  query["continuation-token"] = input.ContinuationToken;
              }
              if (input.Delimiter !== undefined) {
                  query["delimiter"] = input.Delimiter;
              }
              if (input.EncodingType !== undefined) {
                  query["encoding-type"] = input.EncodingType;
              }
              if (input.FetchOwner !== undefined) {
                  query["fetch-owner"] = input.FetchOwner.toString();
              }
              if (input.MaxKeys !== undefined) {
                  query["max-keys"] = input.MaxKeys.toString();
              }
              if (input.Prefix !== undefined) {
                  query["prefix"] = input.Prefix;
              }
              if (input.StartAfter !== undefined) {
                  query["start-after"] = input.StartAfter;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlListPartsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "x-id": "ListParts"
              };
              if (input.MaxParts !== undefined) {
                  query["max-parts"] = input.MaxParts.toString();
              }
              if (input.PartNumberMarker !== undefined) {
                  query["part-number-marker"] = input.PartNumberMarker.toString();
              }
              if (input.UploadId !== undefined) {
                  query["uploadId"] = input.UploadId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "GET", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketAccelerateConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  accelerate: ""
              };
              if (input.AccelerateConfiguration !== undefined) {
                  contents = serializeAws_restXmlAccelerateConfiguration(input.AccelerateConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketAclCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ACL !== undefined) {
                  headers["x-amz-acl"] = input.ACL;
              }
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              if (input.GrantFullControl !== undefined) {
                  headers["x-amz-grant-full-control"] = input.GrantFullControl;
              }
              if (input.GrantRead !== undefined) {
                  headers["x-amz-grant-read"] = input.GrantRead;
              }
              if (input.GrantReadACP !== undefined) {
                  headers["x-amz-grant-read-acp"] = input.GrantReadACP;
              }
              if (input.GrantWrite !== undefined) {
                  headers["x-amz-grant-write"] = input.GrantWrite;
              }
              if (input.GrantWriteACP !== undefined) {
                  headers["x-amz-grant-write-acp"] = input.GrantWriteACP;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  acl: ""
              };
              if (input.AccessControlPolicy !== undefined) {
                  contents = serializeAws_restXmlAccessControlPolicy(input.AccessControlPolicy, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketAnalyticsConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  analytics: ""
              };
              if (input.Id !== undefined) {
                  query["id"] = input.Id;
              }
              if (input.AnalyticsConfiguration !== undefined) {
                  contents = serializeAws_restXmlAnalyticsConfiguration(input.AnalyticsConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketCorsCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  cors: ""
              };
              if (input.CORSConfiguration !== undefined) {
                  contents = serializeAws_restXmlCORSConfiguration(input.CORSConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketEncryptionCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  encryption: ""
              };
              if (input.ServerSideEncryptionConfiguration !== undefined) {
                  contents = serializeAws_restXmlServerSideEncryptionConfiguration(input.ServerSideEncryptionConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketInventoryConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  inventory: ""
              };
              if (input.Id !== undefined) {
                  query["id"] = input.Id;
              }
              if (input.InventoryConfiguration !== undefined) {
                  contents = serializeAws_restXmlInventoryConfiguration(input.InventoryConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketLifecycleConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  lifecycle: ""
              };
              if (input.LifecycleConfiguration !== undefined) {
                  contents = serializeAws_restXmlBucketLifecycleConfiguration(input.LifecycleConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketLoggingCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  logging: ""
              };
              if (input.BucketLoggingStatus !== undefined) {
                  contents = serializeAws_restXmlBucketLoggingStatus(input.BucketLoggingStatus, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketMetricsConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  metrics: ""
              };
              if (input.Id !== undefined) {
                  query["id"] = input.Id;
              }
              if (input.MetricsConfiguration !== undefined) {
                  contents = serializeAws_restXmlMetricsConfiguration(input.MetricsConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketNotificationConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  notification: ""
              };
              if (input.NotificationConfiguration !== undefined) {
                  contents = serializeAws_restXmlNotificationConfiguration(input.NotificationConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketPolicyCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, bodyNode;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ConfirmRemoveSelfBucketAccess !== undefined) {
                  headers["x-amz-confirm-remove-self-bucket-access"] = input.ConfirmRemoveSelfBucketAccess.toString();
              }
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  policy: ""
              };
              body = '<?xml version="1.0" encoding="UTF-8"?>';
              bodyNode = new __XmlNode("PutBucketPolicyRequest");
              bodyNode.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
              if (input.Policy !== undefined) {
                  bodyNode.addChildNode(new __XmlNode("Policy")
                      .addChildNode(new __XmlText(input.Policy))
                      .withName("Policy"));
              }
              body += bodyNode.toString();
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketReplicationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              if (input.Token !== undefined) {
                  headers["x-amz-bucket-object-lock-token"] = input.Token;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  replication: ""
              };
              if (input.ReplicationConfiguration !== undefined) {
                  contents = serializeAws_restXmlReplicationConfiguration(input.ReplicationConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketRequestPaymentCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  requestPayment: ""
              };
              if (input.RequestPaymentConfiguration !== undefined) {
                  contents = serializeAws_restXmlRequestPaymentConfiguration(input.RequestPaymentConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketTaggingCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  tagging: ""
              };
              if (input.Tagging !== undefined) {
                  contents = serializeAws_restXmlTagging(input.Tagging, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketVersioningCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              if (input.MFA !== undefined) {
                  headers["x-amz-mfa"] = input.MFA;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  versioning: ""
              };
              if (input.VersioningConfiguration !== undefined) {
                  contents = serializeAws_restXmlVersioningConfiguration(input.VersioningConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutBucketWebsiteCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  website: ""
              };
              if (input.WebsiteConfiguration !== undefined) {
                  contents = serializeAws_restXmlWebsiteConfiguration(input.WebsiteConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutObjectCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/octet-stream";
              if (input.ACL !== undefined) {
                  headers["x-amz-acl"] = input.ACL;
              }
              if (input.CacheControl !== undefined) {
                  headers["Cache-Control"] = input.CacheControl;
              }
              if (input.ContentDisposition !== undefined) {
                  headers["Content-Disposition"] = input.ContentDisposition;
              }
              if (input.ContentEncoding !== undefined) {
                  headers["Content-Encoding"] = input.ContentEncoding;
              }
              if (input.ContentLanguage !== undefined) {
                  headers["Content-Language"] = input.ContentLanguage;
              }
              if (input.ContentLength !== undefined) {
                  headers["Content-Length"] = input.ContentLength.toString();
              }
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              if (input.ContentType !== undefined) {
                  headers["Content-Type"] = input.ContentType;
              }
              if (input.Expires !== undefined) {
                  headers["Expires"] = __dateToUtcString(input.Expires).toString();
              }
              if (input.GrantFullControl !== undefined) {
                  headers["x-amz-grant-full-control"] = input.GrantFullControl;
              }
              if (input.GrantRead !== undefined) {
                  headers["x-amz-grant-read"] = input.GrantRead;
              }
              if (input.GrantReadACP !== undefined) {
                  headers["x-amz-grant-read-acp"] = input.GrantReadACP;
              }
              if (input.GrantWriteACP !== undefined) {
                  headers["x-amz-grant-write-acp"] = input.GrantWriteACP;
              }
              if (input.ObjectLockLegalHoldStatus !== undefined) {
                  headers["x-amz-object-lock-legal-hold"] = input.ObjectLockLegalHoldStatus;
              }
              if (input.ObjectLockMode !== undefined) {
                  headers["x-amz-object-lock-mode"] = input.ObjectLockMode;
              }
              if (input.ObjectLockRetainUntilDate !== undefined) {
                  headers["x-amz-object-lock-retain-until-date"] = (input.ObjectLockRetainUntilDate.toISOString().split(".")[0] + "Z").toString();
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              if (input.SSECustomerAlgorithm !== undefined) {
                  headers["x-amz-server-side-encryption-customer-algorithm"] =
                      input.SSECustomerAlgorithm;
              }
              if (input.SSECustomerKey !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key"] = input.SSECustomerKey;
              }
              if (input.SSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key-MD5"] =
                      input.SSECustomerKeyMD5;
              }
              if (input.SSEKMSEncryptionContext !== undefined) {
                  headers["x-amz-server-side-encryption-context"] =
                      input.SSEKMSEncryptionContext;
              }
              if (input.SSEKMSKeyId !== undefined) {
                  headers["x-amz-server-side-encryption-aws-kms-key-id"] = input.SSEKMSKeyId;
              }
              if (input.ServerSideEncryption !== undefined) {
                  headers["x-amz-server-side-encryption"] = input.ServerSideEncryption;
              }
              if (input.StorageClass !== undefined) {
                  headers["x-amz-storage-class"] = input.StorageClass;
              }
              if (input.Tagging !== undefined) {
                  headers["x-amz-tagging"] = input.Tagging;
              }
              if (input.WebsiteRedirectLocation !== undefined) {
                  headers["x-amz-website-redirect-location"] = input.WebsiteRedirectLocation;
              }
              if (input.Metadata !== undefined) {
                  Object.keys(input.Metadata).forEach(function (suffix) {
                      headers["x-amz-meta-" + suffix] = input.Metadata[suffix];
                  });
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "x-id": "PutObject"
              };
              if (input.Body !== undefined) {
                  contents = input.Body;
                  body = contents;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutObjectAclCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ACL !== undefined) {
                  headers["x-amz-acl"] = input.ACL;
              }
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              if (input.GrantFullControl !== undefined) {
                  headers["x-amz-grant-full-control"] = input.GrantFullControl;
              }
              if (input.GrantRead !== undefined) {
                  headers["x-amz-grant-read"] = input.GrantRead;
              }
              if (input.GrantReadACP !== undefined) {
                  headers["x-amz-grant-read-acp"] = input.GrantReadACP;
              }
              if (input.GrantWrite !== undefined) {
                  headers["x-amz-grant-write"] = input.GrantWrite;
              }
              if (input.GrantWriteACP !== undefined) {
                  headers["x-amz-grant-write-acp"] = input.GrantWriteACP;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  acl: ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              if (input.AccessControlPolicy !== undefined) {
                  contents = serializeAws_restXmlAccessControlPolicy(input.AccessControlPolicy, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutObjectLegalHoldCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "legal-hold": ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              if (input.LegalHold !== undefined) {
                  contents = serializeAws_restXmlObjectLockLegalHold(input.LegalHold, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutObjectLockConfigurationCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              if (input.Token !== undefined) {
                  headers["x-amz-bucket-object-lock-token"] = input.Token;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  "object-lock": ""
              };
              if (input.ObjectLockConfiguration !== undefined) {
                  contents = serializeAws_restXmlObjectLockConfiguration(input.ObjectLockConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutObjectRetentionCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.BypassGovernanceRetention !== undefined) {
                  headers["x-amz-bypass-governance-retention"] = input.BypassGovernanceRetention.toString();
              }
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  retention: ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              if (input.Retention !== undefined) {
                  contents = serializeAws_restXmlObjectLockRetention(input.Retention, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutObjectTaggingCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  tagging: ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              if (input.Tagging !== undefined) {
                  contents = serializeAws_restXmlTagging(input.Tagging, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlPutPublicAccessBlockCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              resolvedPath = "/{Bucket}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              query = {
                  publicAccessBlock: ""
              };
              if (input.PublicAccessBlockConfiguration !== undefined) {
                  contents = serializeAws_restXmlPublicAccessBlockConfiguration(input.PublicAccessBlockConfiguration, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlRestoreObjectCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  restore: ""
              };
              if (input.VersionId !== undefined) {
                  query["versionId"] = input.VersionId;
              }
              if (input.RestoreRequest !== undefined) {
                  contents = serializeAws_restXmlRestoreRequest(input.RestoreRequest, context);
                  body = '<?xml version="1.0" encoding="UTF-8"?>';
                  contents.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
                  body += contents.toString();
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "POST", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlSelectObjectContentCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body, bodyNode;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/xml";
              if (input.SSECustomerAlgorithm !== undefined) {
                  headers["x-amz-server-side-encryption-customer-algorithm"] =
                      input.SSECustomerAlgorithm;
              }
              if (input.SSECustomerKey !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key"] = input.SSECustomerKey;
              }
              if (input.SSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key-MD5"] =
                      input.SSECustomerKeyMD5;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  select: "",
                  "select-type": "2"
              };
              body = '<?xml version="1.0" encoding="UTF-8"?>';
              bodyNode = new __XmlNode("SelectObjectContentRequest");
              bodyNode.addAttribute("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
              if (input.Expression !== undefined) {
                  bodyNode.addChildNode(new __XmlNode("Expression")
                      .addChildNode(new __XmlText(input.Expression))
                      .withName("Expression"));
              }
              if (input.ExpressionType !== undefined) {
                  bodyNode.addChildNode(new __XmlNode("ExpressionType")
                      .addChildNode(new __XmlText(input.ExpressionType))
                      .withName("ExpressionType"));
              }
              if (input.InputSerialization !== undefined) {
                  bodyNode.addChildNode(serializeAws_restXmlInputSerialization(input.InputSerialization, context).withName("InputSerialization"));
              }
              if (input.OutputSerialization !== undefined) {
                  bodyNode.addChildNode(serializeAws_restXmlOutputSerialization(input.OutputSerialization, context).withName("OutputSerialization"));
              }
              if (input.RequestProgress !== undefined) {
                  bodyNode.addChildNode(serializeAws_restXmlRequestProgress(input.RequestProgress, context).withName("RequestProgress"));
              }
              if (input.ScanRange !== undefined) {
                  bodyNode.addChildNode(serializeAws_restXmlScanRange(input.ScanRange, context).withName("ScanRange"));
              }
              body += bodyNode.toString();
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "POST", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlUploadPartCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body, contents;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "application/octet-stream";
              if (input.ContentLength !== undefined) {
                  headers["Content-Length"] = input.ContentLength.toString();
              }
              if (input.ContentMD5 !== undefined) {
                  headers["Content-MD5"] = input.ContentMD5;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              if (input.SSECustomerAlgorithm !== undefined) {
                  headers["x-amz-server-side-encryption-customer-algorithm"] =
                      input.SSECustomerAlgorithm;
              }
              if (input.SSECustomerKey !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key"] = input.SSECustomerKey;
              }
              if (input.SSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key-MD5"] =
                      input.SSECustomerKeyMD5;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "x-id": "UploadPart"
              };
              if (input.PartNumber !== undefined) {
                  query["partNumber"] = input.PartNumber.toString();
              }
              if (input.UploadId !== undefined) {
                  query["uploadId"] = input.UploadId;
              }
              if (input.Body !== undefined) {
                  contents = input.Body;
                  body = contents;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function serializeAws_restXmlUploadPartCopyCommand(input, context) {
      return __awaiter(this, void 0, void 0, function () {
          var headers, resolvedPath, labelValue, labelValue, query, body;
          return __generator(this, function (_a) {
              headers = {};
              headers["Content-Type"] = "";
              if (input.CopySource !== undefined) {
                  headers["x-amz-copy-source"] = input.CopySource;
              }
              if (input.CopySourceIfMatch !== undefined) {
                  headers["x-amz-copy-source-if-match"] = input.CopySourceIfMatch;
              }
              if (input.CopySourceIfModifiedSince !== undefined) {
                  headers["x-amz-copy-source-if-modified-since"] = __dateToUtcString(input.CopySourceIfModifiedSince).toString();
              }
              if (input.CopySourceIfNoneMatch !== undefined) {
                  headers["x-amz-copy-source-if-none-match"] = input.CopySourceIfNoneMatch;
              }
              if (input.CopySourceIfUnmodifiedSince !== undefined) {
                  headers["x-amz-copy-source-if-unmodified-since"] = __dateToUtcString(input.CopySourceIfUnmodifiedSince).toString();
              }
              if (input.CopySourceRange !== undefined) {
                  headers["x-amz-copy-source-range"] = input.CopySourceRange;
              }
              if (input.CopySourceSSECustomerAlgorithm !== undefined) {
                  headers["x-amz-copy-source-server-side-encryption-customer-algorithm"] =
                      input.CopySourceSSECustomerAlgorithm;
              }
              if (input.CopySourceSSECustomerKey !== undefined) {
                  headers["x-amz-copy-source-server-side-encryption-customer-key"] =
                      input.CopySourceSSECustomerKey;
              }
              if (input.CopySourceSSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-copy-source-server-side-encryption-customer-key-MD5"] =
                      input.CopySourceSSECustomerKeyMD5;
              }
              if (input.RequestPayer !== undefined) {
                  headers["x-amz-request-payer"] = input.RequestPayer;
              }
              if (input.SSECustomerAlgorithm !== undefined) {
                  headers["x-amz-server-side-encryption-customer-algorithm"] =
                      input.SSECustomerAlgorithm;
              }
              if (input.SSECustomerKey !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key"] = input.SSECustomerKey;
              }
              if (input.SSECustomerKeyMD5 !== undefined) {
                  headers["x-amz-server-side-encryption-customer-key-MD5"] =
                      input.SSECustomerKeyMD5;
              }
              resolvedPath = "/{Bucket}/{Key+}";
              if (input.Bucket !== undefined) {
                  labelValue = input.Bucket;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Bucket.");
                  }
                  resolvedPath = resolvedPath.replace("{Bucket}", __extendedEncodeURIComponent(labelValue));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Bucket.");
              }
              if (input.Key !== undefined) {
                  labelValue = input.Key;
                  if (labelValue.length <= 0) {
                      throw new Error("Empty value provided for input HTTP label: Key.");
                  }
                  resolvedPath = resolvedPath.replace("{Key+}", labelValue
                      .split("/")
                      .map(function (segment) { return __extendedEncodeURIComponent(segment); })
                      .join("/"));
              }
              else {
                  throw new Error("No value provided for input HTTP label: Key.");
              }
              query = {
                  "x-id": "UploadPartCopy"
              };
              if (input.PartNumber !== undefined) {
                  query["partNumber"] = input.PartNumber.toString();
              }
              if (input.UploadId !== undefined) {
                  query["uploadId"] = input.UploadId;
              }
              return [2 /*return*/, new __HttpRequest(__assign(__assign({}, context.endpoint), { protocol: "https", method: "PUT", headers: headers, path: resolvedPath, query: query, body: body }))];
          });
      });
  }
  export function deserializeAws_restXmlAbortMultipartUploadCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlAbortMultipartUploadCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "AbortMultipartUploadOutput",
                          RequestCharged: undefined
                      };
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlAbortMultipartUploadCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "NoSuchUpload": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#NoSuchUpload": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlNoSuchUploadResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlCompleteMultipartUploadCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlCompleteMultipartUploadCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "CompleteMultipartUploadOutput",
                          Bucket: undefined,
                          ETag: undefined,
                          Expiration: undefined,
                          Key: undefined,
                          Location: undefined,
                          RequestCharged: undefined,
                          SSEKMSKeyId: undefined,
                          ServerSideEncryption: undefined,
                          VersionId: undefined
                      };
                      if (output.headers["x-amz-expiration"] !== undefined) {
                          contents.Expiration = output.headers["x-amz-expiration"];
                      }
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      if (output.headers["x-amz-server-side-encryption-aws-kms-key-id"] !== undefined) {
                          contents.SSEKMSKeyId =
                              output.headers["x-amz-server-side-encryption-aws-kms-key-id"];
                      }
                      if (output.headers["x-amz-server-side-encryption"] !== undefined) {
                          contents.ServerSideEncryption =
                              output.headers["x-amz-server-side-encryption"];
                      }
                      if (output.headers["x-amz-version-id"] !== undefined) {
                          contents.VersionId = output.headers["x-amz-version-id"];
                      }
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["Bucket"] !== undefined) {
                          contents.Bucket = data["Bucket"];
                      }
                      if (data["ETag"] !== undefined) {
                          contents.ETag = data["ETag"];
                      }
                      if (data["Key"] !== undefined) {
                          contents.Key = data["Key"];
                      }
                      if (data["Location"] !== undefined) {
                          contents.Location = data["Location"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlCompleteMultipartUploadCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlCopyObjectCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlCopyObjectCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "CopyObjectOutput",
                          CopyObjectResult: undefined,
                          CopySourceVersionId: undefined,
                          Expiration: undefined,
                          RequestCharged: undefined,
                          SSECustomerAlgorithm: undefined,
                          SSECustomerKeyMD5: undefined,
                          SSEKMSEncryptionContext: undefined,
                          SSEKMSKeyId: undefined,
                          ServerSideEncryption: undefined,
                          VersionId: undefined
                      };
                      if (output.headers["x-amz-copy-source-version-id"] !== undefined) {
                          contents.CopySourceVersionId =
                              output.headers["x-amz-copy-source-version-id"];
                      }
                      if (output.headers["x-amz-expiration"] !== undefined) {
                          contents.Expiration = output.headers["x-amz-expiration"];
                      }
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-algorithm"] !==
                          undefined) {
                          contents.SSECustomerAlgorithm =
                              output.headers["x-amz-server-side-encryption-customer-algorithm"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-key-md5"] !==
                          undefined) {
                          contents.SSECustomerKeyMD5 =
                              output.headers["x-amz-server-side-encryption-customer-key-md5"];
                      }
                      if (output.headers["x-amz-server-side-encryption-context"] !== undefined) {
                          contents.SSEKMSEncryptionContext =
                              output.headers["x-amz-server-side-encryption-context"];
                      }
                      if (output.headers["x-amz-server-side-encryption-aws-kms-key-id"] !== undefined) {
                          contents.SSEKMSKeyId =
                              output.headers["x-amz-server-side-encryption-aws-kms-key-id"];
                      }
                      if (output.headers["x-amz-server-side-encryption"] !== undefined) {
                          contents.ServerSideEncryption =
                              output.headers["x-amz-server-side-encryption"];
                      }
                      if (output.headers["x-amz-version-id"] !== undefined) {
                          contents.VersionId = output.headers["x-amz-version-id"];
                      }
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.CopyObjectResult = deserializeAws_restXmlCopyObjectResult(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlCopyObjectCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "ObjectNotInActiveTierError": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#ObjectNotInActiveTierError": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlObjectNotInActiveTierErrorResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlCreateBucketCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlCreateBucketCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "CreateBucketOutput",
                          Location: undefined
                      };
                      if (output.headers["location"] !== undefined) {
                          contents.Location = output.headers["location"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlCreateBucketCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, _e, parsedBody, message;
          return __generator(this, function (_f) {
              switch (_f.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _f.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "BucketAlreadyExists": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#BucketAlreadyExists": return [3 /*break*/, 2];
                          case "BucketAlreadyOwnedByYou": return [3 /*break*/, 4];
                          case "com.amazonaws.s3#BucketAlreadyOwnedByYou": return [3 /*break*/, 4];
                      }
                      return [3 /*break*/, 6];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlBucketAlreadyExistsResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_f.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 7];
                  case 4:
                      _e = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlBucketAlreadyOwnedByYouResponse(parsedOutput, context)];
                  case 5:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _e.concat([(_f.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 7];
                  case 6:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _f.label = 7;
                  case 7:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlCreateMultipartUploadCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlCreateMultipartUploadCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "CreateMultipartUploadOutput",
                          AbortDate: undefined,
                          AbortRuleId: undefined,
                          Bucket: undefined,
                          Key: undefined,
                          RequestCharged: undefined,
                          SSECustomerAlgorithm: undefined,
                          SSECustomerKeyMD5: undefined,
                          SSEKMSEncryptionContext: undefined,
                          SSEKMSKeyId: undefined,
                          ServerSideEncryption: undefined,
                          UploadId: undefined
                      };
                      if (output.headers["x-amz-abort-date"] !== undefined) {
                          contents.AbortDate = new Date(output.headers["x-amz-abort-date"]);
                      }
                      if (output.headers["x-amz-abort-rule-id"] !== undefined) {
                          contents.AbortRuleId = output.headers["x-amz-abort-rule-id"];
                      }
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-algorithm"] !==
                          undefined) {
                          contents.SSECustomerAlgorithm =
                              output.headers["x-amz-server-side-encryption-customer-algorithm"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-key-md5"] !==
                          undefined) {
                          contents.SSECustomerKeyMD5 =
                              output.headers["x-amz-server-side-encryption-customer-key-md5"];
                      }
                      if (output.headers["x-amz-server-side-encryption-context"] !== undefined) {
                          contents.SSEKMSEncryptionContext =
                              output.headers["x-amz-server-side-encryption-context"];
                      }
                      if (output.headers["x-amz-server-side-encryption-aws-kms-key-id"] !== undefined) {
                          contents.SSEKMSKeyId =
                              output.headers["x-amz-server-side-encryption-aws-kms-key-id"];
                      }
                      if (output.headers["x-amz-server-side-encryption"] !== undefined) {
                          contents.ServerSideEncryption =
                              output.headers["x-amz-server-side-encryption"];
                      }
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["Bucket"] !== undefined) {
                          contents.Bucket = data["Bucket"];
                      }
                      if (data["Key"] !== undefined) {
                          contents.Key = data["Key"];
                      }
                      if (data["UploadId"] !== undefined) {
                          contents.UploadId = data["UploadId"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlCreateMultipartUploadCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketAnalyticsConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketAnalyticsConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketAnalyticsConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketCorsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketCorsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketCorsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketEncryptionCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketEncryptionCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketEncryptionCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketInventoryConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketInventoryConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketInventoryConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketLifecycleCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketLifecycleCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketLifecycleCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketMetricsConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketMetricsConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketMetricsConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketPolicyCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketPolicyCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketPolicyCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketReplicationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketReplicationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketReplicationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketTaggingCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketTaggingCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketTaggingCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteBucketWebsiteCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteBucketWebsiteCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteBucketWebsiteCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteObjectCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteObjectCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "DeleteObjectOutput",
                          DeleteMarker: undefined,
                          RequestCharged: undefined,
                          VersionId: undefined
                      };
                      if (output.headers["x-amz-delete-marker"] !== undefined) {
                          contents.DeleteMarker = output.headers["x-amz-delete-marker"] === "true";
                      }
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      if (output.headers["x-amz-version-id"] !== undefined) {
                          contents.VersionId = output.headers["x-amz-version-id"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteObjectCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteObjectTaggingCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteObjectTaggingCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "DeleteObjectTaggingOutput",
                          VersionId: undefined
                      };
                      if (output.headers["x-amz-version-id"] !== undefined) {
                          contents.VersionId = output.headers["x-amz-version-id"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteObjectTaggingCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeleteObjectsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeleteObjectsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "DeleteObjectsOutput",
                          Deleted: undefined,
                          Errors: undefined,
                          RequestCharged: undefined
                      };
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.Deleted === "") {
                          contents.Deleted = [];
                      }
                      if (data["Deleted"] !== undefined) {
                          wrappedItem = data["Deleted"] instanceof Array ? data["Deleted"] : [data["Deleted"]];
                          contents.Deleted = deserializeAws_restXmlDeletedObjects(wrappedItem, context);
                      }
                      if (data.Error === "") {
                          contents.Errors = [];
                      }
                      if (data["Error"] !== undefined) {
                          wrappedItem = data["Error"] instanceof Array ? data["Error"] : [data["Error"]];
                          contents.Errors = deserializeAws_restXmlErrors(wrappedItem, context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeleteObjectsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlDeletePublicAccessBlockCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 204 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlDeletePublicAccessBlockCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlDeletePublicAccessBlockCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketAccelerateConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketAccelerateConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketAccelerateConfigurationOutput",
                          Status: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["Status"] !== undefined) {
                          contents.Status = data["Status"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketAccelerateConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketAclCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketAclCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketAclOutput",
                          Grants: undefined,
                          Owner: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.AccessControlList === "") {
                          contents.Grants = [];
                      }
                      if (data["AccessControlList"] !== undefined &&
                          data["AccessControlList"]["Grant"] !== undefined) {
                          wrappedItem = data["AccessControlList"]["Grant"] instanceof Array
                              ? data["AccessControlList"]["Grant"]
                              : [data["AccessControlList"]["Grant"]];
                          contents.Grants = deserializeAws_restXmlGrants(wrappedItem, context);
                      }
                      if (data["Owner"] !== undefined) {
                          contents.Owner = deserializeAws_restXmlOwner(data["Owner"], context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketAclCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketAnalyticsConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketAnalyticsConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketAnalyticsConfigurationOutput",
                          AnalyticsConfiguration: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.AnalyticsConfiguration = deserializeAws_restXmlAnalyticsConfiguration(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketAnalyticsConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketCorsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketCorsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketCorsOutput",
                          CORSRules: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.CORSRule === "") {
                          contents.CORSRules = [];
                      }
                      if (data["CORSRule"] !== undefined) {
                          wrappedItem = data["CORSRule"] instanceof Array ? data["CORSRule"] : [data["CORSRule"]];
                          contents.CORSRules = deserializeAws_restXmlCORSRules(wrappedItem, context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketCorsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketEncryptionCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketEncryptionCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketEncryptionOutput",
                          ServerSideEncryptionConfiguration: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.ServerSideEncryptionConfiguration = deserializeAws_restXmlServerSideEncryptionConfiguration(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketEncryptionCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketInventoryConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketInventoryConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketInventoryConfigurationOutput",
                          InventoryConfiguration: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.InventoryConfiguration = deserializeAws_restXmlInventoryConfiguration(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketInventoryConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketLifecycleConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketLifecycleConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketLifecycleConfigurationOutput",
                          Rules: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.Rule === "") {
                          contents.Rules = [];
                      }
                      if (data["Rule"] !== undefined) {
                          wrappedItem = data["Rule"] instanceof Array ? data["Rule"] : [data["Rule"]];
                          contents.Rules = deserializeAws_restXmlLifecycleRules(wrappedItem, context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketLifecycleConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketLocationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketLocationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketLocationOutput",
                          LocationConstraint: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["LocationConstraint"] !== undefined) {
                          contents.LocationConstraint = data["LocationConstraint"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketLocationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketLoggingCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketLoggingCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketLoggingOutput",
                          LoggingEnabled: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["LoggingEnabled"] !== undefined) {
                          contents.LoggingEnabled = deserializeAws_restXmlLoggingEnabled(data["LoggingEnabled"], context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketLoggingCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketMetricsConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketMetricsConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketMetricsConfigurationOutput",
                          MetricsConfiguration: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.MetricsConfiguration = deserializeAws_restXmlMetricsConfiguration(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketMetricsConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketNotificationConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem, wrappedItem, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketNotificationConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "NotificationConfiguration",
                          LambdaFunctionConfigurations: undefined,
                          QueueConfigurations: undefined,
                          TopicConfigurations: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.CloudFunctionConfiguration === "") {
                          contents.LambdaFunctionConfigurations = [];
                      }
                      if (data["CloudFunctionConfiguration"] !== undefined) {
                          wrappedItem = data["CloudFunctionConfiguration"] instanceof Array
                              ? data["CloudFunctionConfiguration"]
                              : [data["CloudFunctionConfiguration"]];
                          contents.LambdaFunctionConfigurations = deserializeAws_restXmlLambdaFunctionConfigurationList(wrappedItem, context);
                      }
                      if (data.QueueConfiguration === "") {
                          contents.QueueConfigurations = [];
                      }
                      if (data["QueueConfiguration"] !== undefined) {
                          wrappedItem = data["QueueConfiguration"] instanceof Array
                              ? data["QueueConfiguration"]
                              : [data["QueueConfiguration"]];
                          contents.QueueConfigurations = deserializeAws_restXmlQueueConfigurationList(wrappedItem, context);
                      }
                      if (data.TopicConfiguration === "") {
                          contents.TopicConfigurations = [];
                      }
                      if (data["TopicConfiguration"] !== undefined) {
                          wrappedItem = data["TopicConfiguration"] instanceof Array
                              ? data["TopicConfiguration"]
                              : [data["TopicConfiguration"]];
                          contents.TopicConfigurations = deserializeAws_restXmlTopicConfigurationList(wrappedItem, context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketNotificationConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketPolicyCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketPolicyCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketPolicyOutput",
                          Policy: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["Policy"] !== undefined) {
                          contents.Policy = data["Policy"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketPolicyCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketPolicyStatusCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketPolicyStatusCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketPolicyStatusOutput",
                          PolicyStatus: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.PolicyStatus = deserializeAws_restXmlPolicyStatus(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketPolicyStatusCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketReplicationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketReplicationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketReplicationOutput",
                          ReplicationConfiguration: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.ReplicationConfiguration = deserializeAws_restXmlReplicationConfiguration(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketReplicationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketRequestPaymentCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketRequestPaymentCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketRequestPaymentOutput",
                          Payer: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["Payer"] !== undefined) {
                          contents.Payer = data["Payer"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketRequestPaymentCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketTaggingCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketTaggingCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketTaggingOutput",
                          TagSet: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.TagSet === "") {
                          contents.TagSet = [];
                      }
                      if (data["TagSet"] !== undefined && data["TagSet"]["Tag"] !== undefined) {
                          wrappedItem = data["TagSet"]["Tag"] instanceof Array
                              ? data["TagSet"]["Tag"]
                              : [data["TagSet"]["Tag"]];
                          contents.TagSet = deserializeAws_restXmlTagSet(wrappedItem, context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketTaggingCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketVersioningCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketVersioningCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketVersioningOutput",
                          MFADelete: undefined,
                          Status: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["MfaDelete"] !== undefined) {
                          contents.MFADelete = data["MfaDelete"];
                      }
                      if (data["Status"] !== undefined) {
                          contents.Status = data["Status"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketVersioningCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetBucketWebsiteCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetBucketWebsiteCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetBucketWebsiteOutput",
                          ErrorDocument: undefined,
                          IndexDocument: undefined,
                          RedirectAllRequestsTo: undefined,
                          RoutingRules: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["ErrorDocument"] !== undefined) {
                          contents.ErrorDocument = deserializeAws_restXmlErrorDocument(data["ErrorDocument"], context);
                      }
                      if (data["IndexDocument"] !== undefined) {
                          contents.IndexDocument = deserializeAws_restXmlIndexDocument(data["IndexDocument"], context);
                      }
                      if (data["RedirectAllRequestsTo"] !== undefined) {
                          contents.RedirectAllRequestsTo = deserializeAws_restXmlRedirectAllRequestsTo(data["RedirectAllRequestsTo"], context);
                      }
                      if (data.RoutingRules === "") {
                          contents.RoutingRules = [];
                      }
                      if (data["RoutingRules"] !== undefined &&
                          data["RoutingRules"]["RoutingRule"] !== undefined) {
                          wrappedItem = data["RoutingRules"]["RoutingRule"] instanceof Array
                              ? data["RoutingRules"]["RoutingRule"]
                              : [data["RoutingRules"]["RoutingRule"]];
                          contents.RoutingRules = deserializeAws_restXmlRoutingRules(wrappedItem, context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetBucketWebsiteCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetObjectCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              if (output.statusCode !== 200 && output.statusCode >= 400) {
                  return [2 /*return*/, deserializeAws_restXmlGetObjectCommandError(output, context)];
              }
              contents = {
                  $metadata: deserializeMetadata(output),
                  __type: "GetObjectOutput",
                  AcceptRanges: undefined,
                  Body: undefined,
                  CacheControl: undefined,
                  ContentDisposition: undefined,
                  ContentEncoding: undefined,
                  ContentLanguage: undefined,
                  ContentLength: undefined,
                  ContentRange: undefined,
                  ContentType: undefined,
                  DeleteMarker: undefined,
                  ETag: undefined,
                  Expiration: undefined,
                  Expires: undefined,
                  LastModified: undefined,
                  Metadata: undefined,
                  MissingMeta: undefined,
                  ObjectLockLegalHoldStatus: undefined,
                  ObjectLockMode: undefined,
                  ObjectLockRetainUntilDate: undefined,
                  PartsCount: undefined,
                  ReplicationStatus: undefined,
                  RequestCharged: undefined,
                  Restore: undefined,
                  SSECustomerAlgorithm: undefined,
                  SSECustomerKeyMD5: undefined,
                  SSEKMSKeyId: undefined,
                  ServerSideEncryption: undefined,
                  StorageClass: undefined,
                  TagCount: undefined,
                  VersionId: undefined,
                  WebsiteRedirectLocation: undefined
              };
              if (output.headers["accept-ranges"] !== undefined) {
                  contents.AcceptRanges = output.headers["accept-ranges"];
              }
              if (output.headers["cache-control"] !== undefined) {
                  contents.CacheControl = output.headers["cache-control"];
              }
              if (output.headers["content-disposition"] !== undefined) {
                  contents.ContentDisposition = output.headers["content-disposition"];
              }
              if (output.headers["content-encoding"] !== undefined) {
                  contents.ContentEncoding = output.headers["content-encoding"];
              }
              if (output.headers["content-language"] !== undefined) {
                  contents.ContentLanguage = output.headers["content-language"];
              }
              if (output.headers["content-length"] !== undefined) {
                  contents.ContentLength = parseInt(output.headers["content-length"], 10);
              }
              if (output.headers["content-range"] !== undefined) {
                  contents.ContentRange = output.headers["content-range"];
              }
              if (output.headers["content-type"] !== undefined) {
                  contents.ContentType = output.headers["content-type"];
              }
              if (output.headers["x-amz-delete-marker"] !== undefined) {
                  contents.DeleteMarker = output.headers["x-amz-delete-marker"] === "true";
              }
              if (output.headers["etag"] !== undefined) {
                  contents.ETag = output.headers["etag"];
              }
              if (output.headers["x-amz-expiration"] !== undefined) {
                  contents.Expiration = output.headers["x-amz-expiration"];
              }
              if (output.headers["expires"] !== undefined) {
                  contents.Expires = new Date(output.headers["expires"]);
              }
              if (output.headers["last-modified"] !== undefined) {
                  contents.LastModified = new Date(output.headers["last-modified"]);
              }
              if (output.headers["x-amz-missing-meta"] !== undefined) {
                  contents.MissingMeta = parseInt(output.headers["x-amz-missing-meta"], 10);
              }
              if (output.headers["x-amz-object-lock-legal-hold"] !== undefined) {
                  contents.ObjectLockLegalHoldStatus =
                      output.headers["x-amz-object-lock-legal-hold"];
              }
              if (output.headers["x-amz-object-lock-mode"] !== undefined) {
                  contents.ObjectLockMode = output.headers["x-amz-object-lock-mode"];
              }
              if (output.headers["x-amz-object-lock-retain-until-date"] !== undefined) {
                  contents.ObjectLockRetainUntilDate = new Date(output.headers["x-amz-object-lock-retain-until-date"]);
              }
              if (output.headers["x-amz-mp-parts-count"] !== undefined) {
                  contents.PartsCount = parseInt(output.headers["x-amz-mp-parts-count"], 10);
              }
              if (output.headers["x-amz-replication-status"] !== undefined) {
                  contents.ReplicationStatus = output.headers["x-amz-replication-status"];
              }
              if (output.headers["x-amz-request-charged"] !== undefined) {
                  contents.RequestCharged = output.headers["x-amz-request-charged"];
              }
              if (output.headers["x-amz-restore"] !== undefined) {
                  contents.Restore = output.headers["x-amz-restore"];
              }
              if (output.headers["x-amz-server-side-encryption-customer-algorithm"] !==
                  undefined) {
                  contents.SSECustomerAlgorithm =
                      output.headers["x-amz-server-side-encryption-customer-algorithm"];
              }
              if (output.headers["x-amz-server-side-encryption-customer-key-md5"] !==
                  undefined) {
                  contents.SSECustomerKeyMD5 =
                      output.headers["x-amz-server-side-encryption-customer-key-md5"];
              }
              if (output.headers["x-amz-server-side-encryption-aws-kms-key-id"] !== undefined) {
                  contents.SSEKMSKeyId =
                      output.headers["x-amz-server-side-encryption-aws-kms-key-id"];
              }
              if (output.headers["x-amz-server-side-encryption"] !== undefined) {
                  contents.ServerSideEncryption =
                      output.headers["x-amz-server-side-encryption"];
              }
              if (output.headers["x-amz-storage-class"] !== undefined) {
                  contents.StorageClass = output.headers["x-amz-storage-class"];
              }
              if (output.headers["x-amz-tagging-count"] !== undefined) {
                  contents.TagCount = parseInt(output.headers["x-amz-tagging-count"], 10);
              }
              if (output.headers["x-amz-version-id"] !== undefined) {
                  contents.VersionId = output.headers["x-amz-version-id"];
              }
              if (output.headers["x-amz-website-redirect-location"] !== undefined) {
                  contents.WebsiteRedirectLocation =
                      output.headers["x-amz-website-redirect-location"];
              }
              Object.keys(output.headers).forEach(function (header) {
                  if (contents.Metadata === undefined) {
                      contents.Metadata = {};
                  }
                  if (header.startsWith("x-amz-meta-")) {
                      contents.Metadata[header.substring(11)] = output.headers[header];
                  }
              });
              data = output.body;
              contents.Body = data;
              return [2 /*return*/, Promise.resolve(contents)];
          });
      });
  }
  function deserializeAws_restXmlGetObjectCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "NoSuchKey": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#NoSuchKey": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlNoSuchKeyResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetObjectAclCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetObjectAclCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetObjectAclOutput",
                          Grants: undefined,
                          Owner: undefined,
                          RequestCharged: undefined
                      };
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.AccessControlList === "") {
                          contents.Grants = [];
                      }
                      if (data["AccessControlList"] !== undefined &&
                          data["AccessControlList"]["Grant"] !== undefined) {
                          wrappedItem = data["AccessControlList"]["Grant"] instanceof Array
                              ? data["AccessControlList"]["Grant"]
                              : [data["AccessControlList"]["Grant"]];
                          contents.Grants = deserializeAws_restXmlGrants(wrappedItem, context);
                      }
                      if (data["Owner"] !== undefined) {
                          contents.Owner = deserializeAws_restXmlOwner(data["Owner"], context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetObjectAclCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "NoSuchKey": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#NoSuchKey": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlNoSuchKeyResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetObjectLegalHoldCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetObjectLegalHoldCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetObjectLegalHoldOutput",
                          LegalHold: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.LegalHold = deserializeAws_restXmlObjectLockLegalHold(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetObjectLegalHoldCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetObjectLockConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetObjectLockConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetObjectLockConfigurationOutput",
                          ObjectLockConfiguration: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.ObjectLockConfiguration = deserializeAws_restXmlObjectLockConfiguration(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetObjectLockConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetObjectRetentionCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetObjectRetentionCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetObjectRetentionOutput",
                          Retention: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.Retention = deserializeAws_restXmlObjectLockRetention(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetObjectRetentionCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetObjectTaggingCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetObjectTaggingCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetObjectTaggingOutput",
                          TagSet: undefined,
                          VersionId: undefined
                      };
                      if (output.headers["x-amz-version-id"] !== undefined) {
                          contents.VersionId = output.headers["x-amz-version-id"];
                      }
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.TagSet === "") {
                          contents.TagSet = [];
                      }
                      if (data["TagSet"] !== undefined && data["TagSet"]["Tag"] !== undefined) {
                          wrappedItem = data["TagSet"]["Tag"] instanceof Array
                              ? data["TagSet"]["Tag"]
                              : [data["TagSet"]["Tag"]];
                          contents.TagSet = deserializeAws_restXmlTagSet(wrappedItem, context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetObjectTaggingCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetObjectTorrentCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              if (output.statusCode !== 200 && output.statusCode >= 400) {
                  return [2 /*return*/, deserializeAws_restXmlGetObjectTorrentCommandError(output, context)];
              }
              contents = {
                  $metadata: deserializeMetadata(output),
                  __type: "GetObjectTorrentOutput",
                  Body: undefined,
                  RequestCharged: undefined
              };
              if (output.headers["x-amz-request-charged"] !== undefined) {
                  contents.RequestCharged = output.headers["x-amz-request-charged"];
              }
              data = output.body;
              contents.Body = data;
              return [2 /*return*/, Promise.resolve(contents)];
          });
      });
  }
  function deserializeAws_restXmlGetObjectTorrentCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlGetPublicAccessBlockCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlGetPublicAccessBlockCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "GetPublicAccessBlockOutput",
                          PublicAccessBlockConfiguration: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.PublicAccessBlockConfiguration = deserializeAws_restXmlPublicAccessBlockConfiguration(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlGetPublicAccessBlockCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlHeadBucketCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlHeadBucketCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlHeadBucketCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "NoSuchBucket": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#NoSuchBucket": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlNoSuchBucketResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlHeadObjectCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlHeadObjectCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "HeadObjectOutput",
                          AcceptRanges: undefined,
                          CacheControl: undefined,
                          ContentDisposition: undefined,
                          ContentEncoding: undefined,
                          ContentLanguage: undefined,
                          ContentLength: undefined,
                          ContentType: undefined,
                          DeleteMarker: undefined,
                          ETag: undefined,
                          Expiration: undefined,
                          Expires: undefined,
                          LastModified: undefined,
                          Metadata: undefined,
                          MissingMeta: undefined,
                          ObjectLockLegalHoldStatus: undefined,
                          ObjectLockMode: undefined,
                          ObjectLockRetainUntilDate: undefined,
                          PartsCount: undefined,
                          ReplicationStatus: undefined,
                          RequestCharged: undefined,
                          Restore: undefined,
                          SSECustomerAlgorithm: undefined,
                          SSECustomerKeyMD5: undefined,
                          SSEKMSKeyId: undefined,
                          ServerSideEncryption: undefined,
                          StorageClass: undefined,
                          VersionId: undefined,
                          WebsiteRedirectLocation: undefined
                      };
                      if (output.headers["accept-ranges"] !== undefined) {
                          contents.AcceptRanges = output.headers["accept-ranges"];
                      }
                      if (output.headers["cache-control"] !== undefined) {
                          contents.CacheControl = output.headers["cache-control"];
                      }
                      if (output.headers["content-disposition"] !== undefined) {
                          contents.ContentDisposition = output.headers["content-disposition"];
                      }
                      if (output.headers["content-encoding"] !== undefined) {
                          contents.ContentEncoding = output.headers["content-encoding"];
                      }
                      if (output.headers["content-language"] !== undefined) {
                          contents.ContentLanguage = output.headers["content-language"];
                      }
                      if (output.headers["content-length"] !== undefined) {
                          contents.ContentLength = parseInt(output.headers["content-length"], 10);
                      }
                      if (output.headers["content-type"] !== undefined) {
                          contents.ContentType = output.headers["content-type"];
                      }
                      if (output.headers["x-amz-delete-marker"] !== undefined) {
                          contents.DeleteMarker = output.headers["x-amz-delete-marker"] === "true";
                      }
                      if (output.headers["etag"] !== undefined) {
                          contents.ETag = output.headers["etag"];
                      }
                      if (output.headers["x-amz-expiration"] !== undefined) {
                          contents.Expiration = output.headers["x-amz-expiration"];
                      }
                      if (output.headers["expires"] !== undefined) {
                          contents.Expires = new Date(output.headers["expires"]);
                      }
                      if (output.headers["last-modified"] !== undefined) {
                          contents.LastModified = new Date(output.headers["last-modified"]);
                      }
                      if (output.headers["x-amz-missing-meta"] !== undefined) {
                          contents.MissingMeta = parseInt(output.headers["x-amz-missing-meta"], 10);
                      }
                      if (output.headers["x-amz-object-lock-legal-hold"] !== undefined) {
                          contents.ObjectLockLegalHoldStatus =
                              output.headers["x-amz-object-lock-legal-hold"];
                      }
                      if (output.headers["x-amz-object-lock-mode"] !== undefined) {
                          contents.ObjectLockMode = output.headers["x-amz-object-lock-mode"];
                      }
                      if (output.headers["x-amz-object-lock-retain-until-date"] !== undefined) {
                          contents.ObjectLockRetainUntilDate = new Date(output.headers["x-amz-object-lock-retain-until-date"]);
                      }
                      if (output.headers["x-amz-mp-parts-count"] !== undefined) {
                          contents.PartsCount = parseInt(output.headers["x-amz-mp-parts-count"], 10);
                      }
                      if (output.headers["x-amz-replication-status"] !== undefined) {
                          contents.ReplicationStatus = output.headers["x-amz-replication-status"];
                      }
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      if (output.headers["x-amz-restore"] !== undefined) {
                          contents.Restore = output.headers["x-amz-restore"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-algorithm"] !==
                          undefined) {
                          contents.SSECustomerAlgorithm =
                              output.headers["x-amz-server-side-encryption-customer-algorithm"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-key-md5"] !==
                          undefined) {
                          contents.SSECustomerKeyMD5 =
                              output.headers["x-amz-server-side-encryption-customer-key-md5"];
                      }
                      if (output.headers["x-amz-server-side-encryption-aws-kms-key-id"] !== undefined) {
                          contents.SSEKMSKeyId =
                              output.headers["x-amz-server-side-encryption-aws-kms-key-id"];
                      }
                      if (output.headers["x-amz-server-side-encryption"] !== undefined) {
                          contents.ServerSideEncryption =
                              output.headers["x-amz-server-side-encryption"];
                      }
                      if (output.headers["x-amz-storage-class"] !== undefined) {
                          contents.StorageClass = output.headers["x-amz-storage-class"];
                      }
                      if (output.headers["x-amz-version-id"] !== undefined) {
                          contents.VersionId = output.headers["x-amz-version-id"];
                      }
                      if (output.headers["x-amz-website-redirect-location"] !== undefined) {
                          contents.WebsiteRedirectLocation =
                              output.headers["x-amz-website-redirect-location"];
                      }
                      Object.keys(output.headers).forEach(function (header) {
                          if (contents.Metadata === undefined) {
                              contents.Metadata = {};
                          }
                          if (header.startsWith("x-amz-meta-")) {
                              contents.Metadata[header.substring(11)] = output.headers[header];
                          }
                      });
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlHeadObjectCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "NoSuchKey": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#NoSuchKey": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlNoSuchKeyResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlListBucketAnalyticsConfigurationsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlListBucketAnalyticsConfigurationsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "ListBucketAnalyticsConfigurationsOutput",
                          AnalyticsConfigurationList: undefined,
                          ContinuationToken: undefined,
                          IsTruncated: undefined,
                          NextContinuationToken: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.AnalyticsConfiguration === "") {
                          contents.AnalyticsConfigurationList = [];
                      }
                      if (data["AnalyticsConfiguration"] !== undefined) {
                          wrappedItem = data["AnalyticsConfiguration"] instanceof Array
                              ? data["AnalyticsConfiguration"]
                              : [data["AnalyticsConfiguration"]];
                          contents.AnalyticsConfigurationList = deserializeAws_restXmlAnalyticsConfigurationList(wrappedItem, context);
                      }
                      if (data["ContinuationToken"] !== undefined) {
                          contents.ContinuationToken = data["ContinuationToken"];
                      }
                      if (data["IsTruncated"] !== undefined) {
                          contents.IsTruncated = data["IsTruncated"] == "true";
                      }
                      if (data["NextContinuationToken"] !== undefined) {
                          contents.NextContinuationToken = data["NextContinuationToken"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlListBucketAnalyticsConfigurationsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlListBucketInventoryConfigurationsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlListBucketInventoryConfigurationsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "ListBucketInventoryConfigurationsOutput",
                          ContinuationToken: undefined,
                          InventoryConfigurationList: undefined,
                          IsTruncated: undefined,
                          NextContinuationToken: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["ContinuationToken"] !== undefined) {
                          contents.ContinuationToken = data["ContinuationToken"];
                      }
                      if (data.InventoryConfiguration === "") {
                          contents.InventoryConfigurationList = [];
                      }
                      if (data["InventoryConfiguration"] !== undefined) {
                          wrappedItem = data["InventoryConfiguration"] instanceof Array
                              ? data["InventoryConfiguration"]
                              : [data["InventoryConfiguration"]];
                          contents.InventoryConfigurationList = deserializeAws_restXmlInventoryConfigurationList(wrappedItem, context);
                      }
                      if (data["IsTruncated"] !== undefined) {
                          contents.IsTruncated = data["IsTruncated"] == "true";
                      }
                      if (data["NextContinuationToken"] !== undefined) {
                          contents.NextContinuationToken = data["NextContinuationToken"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlListBucketInventoryConfigurationsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlListBucketMetricsConfigurationsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlListBucketMetricsConfigurationsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "ListBucketMetricsConfigurationsOutput",
                          ContinuationToken: undefined,
                          IsTruncated: undefined,
                          MetricsConfigurationList: undefined,
                          NextContinuationToken: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["ContinuationToken"] !== undefined) {
                          contents.ContinuationToken = data["ContinuationToken"];
                      }
                      if (data["IsTruncated"] !== undefined) {
                          contents.IsTruncated = data["IsTruncated"] == "true";
                      }
                      if (data.MetricsConfiguration === "") {
                          contents.MetricsConfigurationList = [];
                      }
                      if (data["MetricsConfiguration"] !== undefined) {
                          wrappedItem = data["MetricsConfiguration"] instanceof Array
                              ? data["MetricsConfiguration"]
                              : [data["MetricsConfiguration"]];
                          contents.MetricsConfigurationList = deserializeAws_restXmlMetricsConfigurationList(wrappedItem, context);
                      }
                      if (data["NextContinuationToken"] !== undefined) {
                          contents.NextContinuationToken = data["NextContinuationToken"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlListBucketMetricsConfigurationsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlListBucketsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlListBucketsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "ListBucketsOutput",
                          Buckets: undefined,
                          Owner: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.Buckets === "") {
                          contents.Buckets = [];
                      }
                      if (data["Buckets"] !== undefined &&
                          data["Buckets"]["Bucket"] !== undefined) {
                          wrappedItem = data["Buckets"]["Bucket"] instanceof Array
                              ? data["Buckets"]["Bucket"]
                              : [data["Buckets"]["Bucket"]];
                          contents.Buckets = deserializeAws_restXmlBuckets(wrappedItem, context);
                      }
                      if (data["Owner"] !== undefined) {
                          contents.Owner = deserializeAws_restXmlOwner(data["Owner"], context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlListBucketsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlListMultipartUploadsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlListMultipartUploadsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "ListMultipartUploadsOutput",
                          Bucket: undefined,
                          CommonPrefixes: undefined,
                          Delimiter: undefined,
                          EncodingType: undefined,
                          IsTruncated: undefined,
                          KeyMarker: undefined,
                          MaxUploads: undefined,
                          NextKeyMarker: undefined,
                          NextUploadIdMarker: undefined,
                          Prefix: undefined,
                          UploadIdMarker: undefined,
                          Uploads: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["Bucket"] !== undefined) {
                          contents.Bucket = data["Bucket"];
                      }
                      if (data.CommonPrefixes === "") {
                          contents.CommonPrefixes = [];
                      }
                      if (data["CommonPrefixes"] !== undefined) {
                          wrappedItem = data["CommonPrefixes"] instanceof Array
                              ? data["CommonPrefixes"]
                              : [data["CommonPrefixes"]];
                          contents.CommonPrefixes = deserializeAws_restXmlCommonPrefixList(wrappedItem, context);
                      }
                      if (data["Delimiter"] !== undefined) {
                          contents.Delimiter = data["Delimiter"];
                      }
                      if (data["EncodingType"] !== undefined) {
                          contents.EncodingType = data["EncodingType"];
                      }
                      if (data["IsTruncated"] !== undefined) {
                          contents.IsTruncated = data["IsTruncated"] == "true";
                      }
                      if (data["KeyMarker"] !== undefined) {
                          contents.KeyMarker = data["KeyMarker"];
                      }
                      if (data["MaxUploads"] !== undefined) {
                          contents.MaxUploads = parseInt(data["MaxUploads"]);
                      }
                      if (data["NextKeyMarker"] !== undefined) {
                          contents.NextKeyMarker = data["NextKeyMarker"];
                      }
                      if (data["NextUploadIdMarker"] !== undefined) {
                          contents.NextUploadIdMarker = data["NextUploadIdMarker"];
                      }
                      if (data["Prefix"] !== undefined) {
                          contents.Prefix = data["Prefix"];
                      }
                      if (data["UploadIdMarker"] !== undefined) {
                          contents.UploadIdMarker = data["UploadIdMarker"];
                      }
                      if (data.Upload === "") {
                          contents.Uploads = [];
                      }
                      if (data["Upload"] !== undefined) {
                          wrappedItem = data["Upload"] instanceof Array ? data["Upload"] : [data["Upload"]];
                          contents.Uploads = deserializeAws_restXmlMultipartUploadList(wrappedItem, context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlListMultipartUploadsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlListObjectVersionsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem, wrappedItem, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlListObjectVersionsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "ListObjectVersionsOutput",
                          CommonPrefixes: undefined,
                          DeleteMarkers: undefined,
                          Delimiter: undefined,
                          EncodingType: undefined,
                          IsTruncated: undefined,
                          KeyMarker: undefined,
                          MaxKeys: undefined,
                          Name: undefined,
                          NextKeyMarker: undefined,
                          NextVersionIdMarker: undefined,
                          Prefix: undefined,
                          VersionIdMarker: undefined,
                          Versions: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.CommonPrefixes === "") {
                          contents.CommonPrefixes = [];
                      }
                      if (data["CommonPrefixes"] !== undefined) {
                          wrappedItem = data["CommonPrefixes"] instanceof Array
                              ? data["CommonPrefixes"]
                              : [data["CommonPrefixes"]];
                          contents.CommonPrefixes = deserializeAws_restXmlCommonPrefixList(wrappedItem, context);
                      }
                      if (data.DeleteMarker === "") {
                          contents.DeleteMarkers = [];
                      }
                      if (data["DeleteMarker"] !== undefined) {
                          wrappedItem = data["DeleteMarker"] instanceof Array
                              ? data["DeleteMarker"]
                              : [data["DeleteMarker"]];
                          contents.DeleteMarkers = deserializeAws_restXmlDeleteMarkers(wrappedItem, context);
                      }
                      if (data["Delimiter"] !== undefined) {
                          contents.Delimiter = data["Delimiter"];
                      }
                      if (data["EncodingType"] !== undefined) {
                          contents.EncodingType = data["EncodingType"];
                      }
                      if (data["IsTruncated"] !== undefined) {
                          contents.IsTruncated = data["IsTruncated"] == "true";
                      }
                      if (data["KeyMarker"] !== undefined) {
                          contents.KeyMarker = data["KeyMarker"];
                      }
                      if (data["MaxKeys"] !== undefined) {
                          contents.MaxKeys = parseInt(data["MaxKeys"]);
                      }
                      if (data["Name"] !== undefined) {
                          contents.Name = data["Name"];
                      }
                      if (data["NextKeyMarker"] !== undefined) {
                          contents.NextKeyMarker = data["NextKeyMarker"];
                      }
                      if (data["NextVersionIdMarker"] !== undefined) {
                          contents.NextVersionIdMarker = data["NextVersionIdMarker"];
                      }
                      if (data["Prefix"] !== undefined) {
                          contents.Prefix = data["Prefix"];
                      }
                      if (data["VersionIdMarker"] !== undefined) {
                          contents.VersionIdMarker = data["VersionIdMarker"];
                      }
                      if (data.Version === "") {
                          contents.Versions = [];
                      }
                      if (data["Version"] !== undefined) {
                          wrappedItem = data["Version"] instanceof Array ? data["Version"] : [data["Version"]];
                          contents.Versions = deserializeAws_restXmlObjectVersionList(wrappedItem, context);
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlListObjectVersionsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlListObjectsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlListObjectsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "ListObjectsOutput",
                          CommonPrefixes: undefined,
                          Contents: undefined,
                          Delimiter: undefined,
                          EncodingType: undefined,
                          IsTruncated: undefined,
                          Marker: undefined,
                          MaxKeys: undefined,
                          Name: undefined,
                          NextMarker: undefined,
                          Prefix: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.CommonPrefixes === "") {
                          contents.CommonPrefixes = [];
                      }
                      if (data["CommonPrefixes"] !== undefined) {
                          wrappedItem = data["CommonPrefixes"] instanceof Array
                              ? data["CommonPrefixes"]
                              : [data["CommonPrefixes"]];
                          contents.CommonPrefixes = deserializeAws_restXmlCommonPrefixList(wrappedItem, context);
                      }
                      if (data.Contents === "") {
                          contents.Contents = [];
                      }
                      if (data["Contents"] !== undefined) {
                          wrappedItem = data["Contents"] instanceof Array ? data["Contents"] : [data["Contents"]];
                          contents.Contents = deserializeAws_restXmlObjectList(wrappedItem, context);
                      }
                      if (data["Delimiter"] !== undefined) {
                          contents.Delimiter = data["Delimiter"];
                      }
                      if (data["EncodingType"] !== undefined) {
                          contents.EncodingType = data["EncodingType"];
                      }
                      if (data["IsTruncated"] !== undefined) {
                          contents.IsTruncated = data["IsTruncated"] == "true";
                      }
                      if (data["Marker"] !== undefined) {
                          contents.Marker = data["Marker"];
                      }
                      if (data["MaxKeys"] !== undefined) {
                          contents.MaxKeys = parseInt(data["MaxKeys"]);
                      }
                      if (data["Name"] !== undefined) {
                          contents.Name = data["Name"];
                      }
                      if (data["NextMarker"] !== undefined) {
                          contents.NextMarker = data["NextMarker"];
                      }
                      if (data["Prefix"] !== undefined) {
                          contents.Prefix = data["Prefix"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlListObjectsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "NoSuchBucket": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#NoSuchBucket": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlNoSuchBucketResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlListObjectsV2Command(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlListObjectsV2CommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "ListObjectsV2Output",
                          CommonPrefixes: undefined,
                          Contents: undefined,
                          ContinuationToken: undefined,
                          Delimiter: undefined,
                          EncodingType: undefined,
                          IsTruncated: undefined,
                          KeyCount: undefined,
                          MaxKeys: undefined,
                          Name: undefined,
                          NextContinuationToken: undefined,
                          Prefix: undefined,
                          StartAfter: undefined
                      };
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data.CommonPrefixes === "") {
                          contents.CommonPrefixes = [];
                      }
                      if (data["CommonPrefixes"] !== undefined) {
                          wrappedItem = data["CommonPrefixes"] instanceof Array
                              ? data["CommonPrefixes"]
                              : [data["CommonPrefixes"]];
                          contents.CommonPrefixes = deserializeAws_restXmlCommonPrefixList(wrappedItem, context);
                      }
                      if (data.Contents === "") {
                          contents.Contents = [];
                      }
                      if (data["Contents"] !== undefined) {
                          wrappedItem = data["Contents"] instanceof Array ? data["Contents"] : [data["Contents"]];
                          contents.Contents = deserializeAws_restXmlObjectList(wrappedItem, context);
                      }
                      if (data["ContinuationToken"] !== undefined) {
                          contents.ContinuationToken = data["ContinuationToken"];
                      }
                      if (data["Delimiter"] !== undefined) {
                          contents.Delimiter = data["Delimiter"];
                      }
                      if (data["EncodingType"] !== undefined) {
                          contents.EncodingType = data["EncodingType"];
                      }
                      if (data["IsTruncated"] !== undefined) {
                          contents.IsTruncated = data["IsTruncated"] == "true";
                      }
                      if (data["KeyCount"] !== undefined) {
                          contents.KeyCount = parseInt(data["KeyCount"]);
                      }
                      if (data["MaxKeys"] !== undefined) {
                          contents.MaxKeys = parseInt(data["MaxKeys"]);
                      }
                      if (data["Name"] !== undefined) {
                          contents.Name = data["Name"];
                      }
                      if (data["NextContinuationToken"] !== undefined) {
                          contents.NextContinuationToken = data["NextContinuationToken"];
                      }
                      if (data["Prefix"] !== undefined) {
                          contents.Prefix = data["Prefix"];
                      }
                      if (data["StartAfter"] !== undefined) {
                          contents.StartAfter = data["StartAfter"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlListObjectsV2CommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "NoSuchBucket": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#NoSuchBucket": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlNoSuchBucketResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlListPartsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data, wrappedItem;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlListPartsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "ListPartsOutput",
                          AbortDate: undefined,
                          AbortRuleId: undefined,
                          Bucket: undefined,
                          Initiator: undefined,
                          IsTruncated: undefined,
                          Key: undefined,
                          MaxParts: undefined,
                          NextPartNumberMarker: undefined,
                          Owner: undefined,
                          PartNumberMarker: undefined,
                          Parts: undefined,
                          RequestCharged: undefined,
                          StorageClass: undefined,
                          UploadId: undefined
                      };
                      if (output.headers["x-amz-abort-date"] !== undefined) {
                          contents.AbortDate = new Date(output.headers["x-amz-abort-date"]);
                      }
                      if (output.headers["x-amz-abort-rule-id"] !== undefined) {
                          contents.AbortRuleId = output.headers["x-amz-abort-rule-id"];
                      }
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      if (data["Bucket"] !== undefined) {
                          contents.Bucket = data["Bucket"];
                      }
                      if (data["Initiator"] !== undefined) {
                          contents.Initiator = deserializeAws_restXmlInitiator(data["Initiator"], context);
                      }
                      if (data["IsTruncated"] !== undefined) {
                          contents.IsTruncated = data["IsTruncated"] == "true";
                      }
                      if (data["Key"] !== undefined) {
                          contents.Key = data["Key"];
                      }
                      if (data["MaxParts"] !== undefined) {
                          contents.MaxParts = parseInt(data["MaxParts"]);
                      }
                      if (data["NextPartNumberMarker"] !== undefined) {
                          contents.NextPartNumberMarker = parseInt(data["NextPartNumberMarker"]);
                      }
                      if (data["Owner"] !== undefined) {
                          contents.Owner = deserializeAws_restXmlOwner(data["Owner"], context);
                      }
                      if (data["PartNumberMarker"] !== undefined) {
                          contents.PartNumberMarker = parseInt(data["PartNumberMarker"]);
                      }
                      if (data.Part === "") {
                          contents.Parts = [];
                      }
                      if (data["Part"] !== undefined) {
                          wrappedItem = data["Part"] instanceof Array ? data["Part"] : [data["Part"]];
                          contents.Parts = deserializeAws_restXmlParts(wrappedItem, context);
                      }
                      if (data["StorageClass"] !== undefined) {
                          contents.StorageClass = data["StorageClass"];
                      }
                      if (data["UploadId"] !== undefined) {
                          contents.UploadId = data["UploadId"];
                      }
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlListPartsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketAccelerateConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketAccelerateConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketAccelerateConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketAclCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketAclCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketAclCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketAnalyticsConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketAnalyticsConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketAnalyticsConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketCorsCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketCorsCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketCorsCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketEncryptionCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketEncryptionCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketEncryptionCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketInventoryConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketInventoryConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketInventoryConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketLifecycleConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketLifecycleConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketLifecycleConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketLoggingCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketLoggingCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketLoggingCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketMetricsConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketMetricsConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketMetricsConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketNotificationConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketNotificationConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketNotificationConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketPolicyCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketPolicyCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketPolicyCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketReplicationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketReplicationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketReplicationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketRequestPaymentCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketRequestPaymentCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketRequestPaymentCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketTaggingCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketTaggingCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketTaggingCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketVersioningCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketVersioningCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketVersioningCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutBucketWebsiteCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutBucketWebsiteCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutBucketWebsiteCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutObjectCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutObjectCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "PutObjectOutput",
                          ETag: undefined,
                          Expiration: undefined,
                          RequestCharged: undefined,
                          SSECustomerAlgorithm: undefined,
                          SSECustomerKeyMD5: undefined,
                          SSEKMSEncryptionContext: undefined,
                          SSEKMSKeyId: undefined,
                          ServerSideEncryption: undefined,
                          VersionId: undefined
                      };
                      if (output.headers["etag"] !== undefined) {
                          contents.ETag = output.headers["etag"];
                      }
                      if (output.headers["x-amz-expiration"] !== undefined) {
                          contents.Expiration = output.headers["x-amz-expiration"];
                      }
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-algorithm"] !==
                          undefined) {
                          contents.SSECustomerAlgorithm =
                              output.headers["x-amz-server-side-encryption-customer-algorithm"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-key-md5"] !==
                          undefined) {
                          contents.SSECustomerKeyMD5 =
                              output.headers["x-amz-server-side-encryption-customer-key-md5"];
                      }
                      if (output.headers["x-amz-server-side-encryption-context"] !== undefined) {
                          contents.SSEKMSEncryptionContext =
                              output.headers["x-amz-server-side-encryption-context"];
                      }
                      if (output.headers["x-amz-server-side-encryption-aws-kms-key-id"] !== undefined) {
                          contents.SSEKMSKeyId =
                              output.headers["x-amz-server-side-encryption-aws-kms-key-id"];
                      }
                      if (output.headers["x-amz-server-side-encryption"] !== undefined) {
                          contents.ServerSideEncryption =
                              output.headers["x-amz-server-side-encryption"];
                      }
                      if (output.headers["x-amz-version-id"] !== undefined) {
                          contents.VersionId = output.headers["x-amz-version-id"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutObjectCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutObjectAclCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutObjectAclCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "PutObjectAclOutput",
                          RequestCharged: undefined
                      };
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutObjectAclCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "NoSuchKey": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#NoSuchKey": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlNoSuchKeyResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutObjectLegalHoldCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutObjectLegalHoldCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "PutObjectLegalHoldOutput",
                          RequestCharged: undefined
                      };
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutObjectLegalHoldCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutObjectLockConfigurationCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutObjectLockConfigurationCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "PutObjectLockConfigurationOutput",
                          RequestCharged: undefined
                      };
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutObjectLockConfigurationCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutObjectRetentionCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutObjectRetentionCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "PutObjectRetentionOutput",
                          RequestCharged: undefined
                      };
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutObjectRetentionCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutObjectTaggingCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutObjectTaggingCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "PutObjectTaggingOutput",
                          VersionId: undefined
                      };
                      if (output.headers["x-amz-version-id"] !== undefined) {
                          contents.VersionId = output.headers["x-amz-version-id"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutObjectTaggingCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlPutPublicAccessBlockCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlPutPublicAccessBlockCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output)
                      };
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlPutPublicAccessBlockCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlRestoreObjectCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlRestoreObjectCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "RestoreObjectOutput",
                          RequestCharged: undefined,
                          RestoreOutputPath: undefined
                      };
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      if (output.headers["x-amz-restore-output-path"] !== undefined) {
                          contents.RestoreOutputPath = output.headers["x-amz-restore-output-path"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlRestoreObjectCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, _c, _d, parsedBody, message;
          return __generator(this, function (_e) {
              switch (_e.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _e.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      _c = errorCode;
                      switch (_c) {
                          case "ObjectAlreadyInActiveTierError": return [3 /*break*/, 2];
                          case "com.amazonaws.s3#ObjectAlreadyInActiveTierError": return [3 /*break*/, 2];
                      }
                      return [3 /*break*/, 4];
                  case 2:
                      _d = [{}];
                      return [4 /*yield*/, deserializeAws_restXmlObjectAlreadyInActiveTierErrorResponse(parsedOutput, context)];
                  case 3:
                      response = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { name: errorCode, $metadata: deserializeMetadata(output) }]);
                      return [3 /*break*/, 5];
                  case 4:
                      parsedBody = parsedOutput.body;
                      errorCode = parsedBody.code || parsedBody.Code || errorCode;
                      response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      _e.label = 5;
                  case 5:
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlSelectObjectContentCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          var _this = this;
          return __generator(this, function (_a) {
              if (output.statusCode !== 200 && output.statusCode >= 400) {
                  return [2 /*return*/, deserializeAws_restXmlSelectObjectContentCommandError(output, context)];
              }
              contents = {
                  $metadata: deserializeMetadata(output),
                  __type: "SelectObjectContentOutput",
                  Payload: undefined
              };
              data = context.eventStreamMarshaller.deserialize(output.body, function (event) { return __awaiter(_this, void 0, void 0, function () {
                  var eventName, eventHeaders, eventMessage, parsedEvent;
                  var _a;
                  return __generator(this, function (_b) {
                      switch (_b.label) {
                          case 0:
                              eventName = Object.keys(event)[0];
                              eventHeaders = Object.entries(event[eventName].headers).reduce(function (accummulator, curr) {
                                  accummulator[curr[0]] = curr[1].value;
                                  return accummulator;
                              }, {});
                              eventMessage = {
                                  headers: eventHeaders,
                                  body: event[eventName].body
                              };
                              parsedEvent = (_a = {},
                                  _a[eventName] = eventMessage,
                                  _a);
                              return [4 /*yield*/, deserializeAws_restXmlSelectObjectContentEventStream_event(parsedEvent, context)];
                          case 1: return [2 /*return*/, _b.sent()];
                      }
                  });
              }); });
              contents.Payload = data;
              return [2 /*return*/, Promise.resolve(contents)];
          });
      });
  }
  function deserializeAws_restXmlSelectObjectContentCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlUploadPartCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlUploadPartCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "UploadPartOutput",
                          ETag: undefined,
                          RequestCharged: undefined,
                          SSECustomerAlgorithm: undefined,
                          SSECustomerKeyMD5: undefined,
                          SSEKMSKeyId: undefined,
                          ServerSideEncryption: undefined
                      };
                      if (output.headers["etag"] !== undefined) {
                          contents.ETag = output.headers["etag"];
                      }
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-algorithm"] !==
                          undefined) {
                          contents.SSECustomerAlgorithm =
                              output.headers["x-amz-server-side-encryption-customer-algorithm"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-key-md5"] !==
                          undefined) {
                          contents.SSECustomerKeyMD5 =
                              output.headers["x-amz-server-side-encryption-customer-key-md5"];
                      }
                      if (output.headers["x-amz-server-side-encryption-aws-kms-key-id"] !== undefined) {
                          contents.SSEKMSKeyId =
                              output.headers["x-amz-server-side-encryption-aws-kms-key-id"];
                      }
                      if (output.headers["x-amz-server-side-encryption"] !== undefined) {
                          contents.ServerSideEncryption =
                              output.headers["x-amz-server-side-encryption"];
                      }
                      return [4 /*yield*/, collectBody(output.body, context)];
                  case 1:
                      _a.sent();
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlUploadPartCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  export function deserializeAws_restXmlUploadPartCopyCommand(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var contents, data;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      if (output.statusCode !== 200 && output.statusCode >= 400) {
                          return [2 /*return*/, deserializeAws_restXmlUploadPartCopyCommandError(output, context)];
                      }
                      contents = {
                          $metadata: deserializeMetadata(output),
                          __type: "UploadPartCopyOutput",
                          CopyPartResult: undefined,
                          CopySourceVersionId: undefined,
                          RequestCharged: undefined,
                          SSECustomerAlgorithm: undefined,
                          SSECustomerKeyMD5: undefined,
                          SSEKMSKeyId: undefined,
                          ServerSideEncryption: undefined
                      };
                      if (output.headers["x-amz-copy-source-version-id"] !== undefined) {
                          contents.CopySourceVersionId =
                              output.headers["x-amz-copy-source-version-id"];
                      }
                      if (output.headers["x-amz-request-charged"] !== undefined) {
                          contents.RequestCharged = output.headers["x-amz-request-charged"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-algorithm"] !==
                          undefined) {
                          contents.SSECustomerAlgorithm =
                              output.headers["x-amz-server-side-encryption-customer-algorithm"];
                      }
                      if (output.headers["x-amz-server-side-encryption-customer-key-md5"] !==
                          undefined) {
                          contents.SSECustomerKeyMD5 =
                              output.headers["x-amz-server-side-encryption-customer-key-md5"];
                      }
                      if (output.headers["x-amz-server-side-encryption-aws-kms-key-id"] !== undefined) {
                          contents.SSEKMSKeyId =
                              output.headers["x-amz-server-side-encryption-aws-kms-key-id"];
                      }
                      if (output.headers["x-amz-server-side-encryption"] !== undefined) {
                          contents.ServerSideEncryption =
                              output.headers["x-amz-server-side-encryption"];
                      }
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      data = _a.sent();
                      contents.CopyPartResult = deserializeAws_restXmlCopyPartResult(data, context);
                      return [2 /*return*/, Promise.resolve(contents)];
              }
          });
      });
  }
  function deserializeAws_restXmlUploadPartCopyCommandError(output, context) {
      return __awaiter(this, void 0, void 0, function () {
          var parsedOutput, _a, _b, response, errorCode, parsedBody, message;
          return __generator(this, function (_c) {
              switch (_c.label) {
                  case 0:
                      _a = [__assign({}, output)];
                      _b = {};
                      return [4 /*yield*/, parseBody(output.body, context)];
                  case 1:
                      parsedOutput = __assign.apply(void 0, _a.concat([(_b.body = _c.sent(), _b)]));
                      errorCode = "UnknownError";
                      errorCode = loadRestXmlErrorCode(output, parsedOutput.body);
                      switch (errorCode) {
                          default:
                              parsedBody = parsedOutput.body;
                              errorCode = parsedBody.code || parsedBody.Code || errorCode;
                              response = __assign(__assign({}, parsedBody), { name: "" + errorCode, message: parsedBody.message || parsedBody.Message || errorCode, $fault: "client", $metadata: deserializeMetadata(output) });
                      }
                      message = response.message || response.Message || errorCode;
                      response.message = message;
                      delete response.Message;
                      return [2 /*return*/, Promise.reject(Object.assign(new Error(message), response))];
              }
          });
      });
  }
  var deserializeAws_restXmlSelectObjectContentEventStream_event = function (output, context) { return __awaiter(void 0, void 0, void 0, function () {
      var _a, _b, _c, _d, _e;
      return __generator(this, function (_f) {
          switch (_f.label) {
              case 0:
                  if (!(output["Cont"] !== undefined)) return [3 /*break*/, 2];
                  _a = {};
                  return [4 /*yield*/, deserializeAws_restXmlContinuationEvent_event(output["Cont"], context)];
              case 1: return [2 /*return*/, (_a.Cont = _f.sent(),
                      _a)];
              case 2:
                  if (!(output["End"] !== undefined)) return [3 /*break*/, 4];
                  _b = {};
                  return [4 /*yield*/, deserializeAws_restXmlEndEvent_event(output["End"], context)];
              case 3: return [2 /*return*/, (_b.End = _f.sent(),
                      _b)];
              case 4:
                  if (!(output["Progress"] !== undefined)) return [3 /*break*/, 6];
                  _c = {};
                  return [4 /*yield*/, deserializeAws_restXmlProgressEvent_event(output["Progress"], context)];
              case 5: return [2 /*return*/, (_c.Progress = _f.sent(),
                      _c)];
              case 6:
                  if (!(output["Records"] !== undefined)) return [3 /*break*/, 8];
                  _d = {};
                  return [4 /*yield*/, deserializeAws_restXmlRecordsEvent_event(output["Records"], context)];
              case 7: return [2 /*return*/, (_d.Records = _f.sent(),
                      _d)];
              case 8:
                  if (!(output["Stats"] !== undefined)) return [3 /*break*/, 10];
                  _e = {};
                  return [4 /*yield*/, deserializeAws_restXmlStatsEvent_event(output["Stats"], context)];
              case 9: return [2 /*return*/, (_e.Stats = _f.sent(),
                      _e)];
              case 10: return [2 /*return*/, { $unknown: output }];
          }
      });
  }); };
  var deserializeAws_restXmlContinuationEvent_event = function (output, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents;
      return __generator(this, function (_a) {
          contents = {};
          return [2 /*return*/, contents];
      });
  }); };
  var deserializeAws_restXmlEndEvent_event = function (output, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents;
      return __generator(this, function (_a) {
          contents = {};
          return [2 /*return*/, contents];
      });
  }); };
  var deserializeAws_restXmlProgressEvent_event = function (output, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents, _a;
      return __generator(this, function (_b) {
          switch (_b.label) {
              case 0:
                  contents = {
                      __type: "ProgressEvent"
                  };
                  _a = contents;
                  return [4 /*yield*/, parseBody(output.body, context)];
              case 1:
                  _a.Details = _b.sent();
                  return [2 /*return*/, contents];
          }
      });
  }); };
  var deserializeAws_restXmlRecordsEvent_event = function (output, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents;
      return __generator(this, function (_a) {
          contents = {
              __type: "RecordsEvent"
          };
          contents.Payload = output.body;
          return [2 /*return*/, contents];
      });
  }); };
  var deserializeAws_restXmlStatsEvent_event = function (output, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents, _a;
      return __generator(this, function (_b) {
          switch (_b.label) {
              case 0:
                  contents = {
                      __type: "StatsEvent"
                  };
                  _a = contents;
                  return [4 /*yield*/, parseBody(output.body, context)];
              case 1:
                  _a.Details = _b.sent();
                  return [2 /*return*/, contents];
          }
      });
  }); };
  var deserializeAws_restXmlBucketAlreadyExistsResponse = function (parsedOutput, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents, data;
      return __generator(this, function (_a) {
          contents = {
              name: "BucketAlreadyExists",
              $fault: "client",
              $metadata: deserializeMetadata(parsedOutput)
          };
          data = parsedOutput.body;
          return [2 /*return*/, contents];
      });
  }); };
  var deserializeAws_restXmlBucketAlreadyOwnedByYouResponse = function (parsedOutput, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents, data;
      return __generator(this, function (_a) {
          contents = {
              name: "BucketAlreadyOwnedByYou",
              $fault: "client",
              $metadata: deserializeMetadata(parsedOutput)
          };
          data = parsedOutput.body;
          return [2 /*return*/, contents];
      });
  }); };
  var deserializeAws_restXmlNoSuchBucketResponse = function (parsedOutput, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents, data;
      return __generator(this, function (_a) {
          contents = {
              name: "NoSuchBucket",
              $fault: "client",
              $metadata: deserializeMetadata(parsedOutput)
          };
          data = parsedOutput.body;
          return [2 /*return*/, contents];
      });
  }); };
  var deserializeAws_restXmlNoSuchKeyResponse = function (parsedOutput, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents, data;
      return __generator(this, function (_a) {
          contents = {
              name: "NoSuchKey",
              $fault: "client",
              $metadata: deserializeMetadata(parsedOutput)
          };
          data = parsedOutput.body;
          return [2 /*return*/, contents];
      });
  }); };
  var deserializeAws_restXmlNoSuchUploadResponse = function (parsedOutput, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents, data;
      return __generator(this, function (_a) {
          contents = {
              name: "NoSuchUpload",
              $fault: "client",
              $metadata: deserializeMetadata(parsedOutput)
          };
          data = parsedOutput.body;
          return [2 /*return*/, contents];
      });
  }); };
  var deserializeAws_restXmlObjectAlreadyInActiveTierErrorResponse = function (parsedOutput, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents, data;
      return __generator(this, function (_a) {
          contents = {
              name: "ObjectAlreadyInActiveTierError",
              $fault: "client",
              $metadata: deserializeMetadata(parsedOutput)
          };
          data = parsedOutput.body;
          return [2 /*return*/, contents];
      });
  }); };
  var deserializeAws_restXmlObjectNotInActiveTierErrorResponse = function (parsedOutput, context) { return __awaiter(void 0, void 0, void 0, function () {
      var contents, data;
      return __generator(this, function (_a) {
          contents = {
              name: "ObjectNotInActiveTierError",
              $fault: "client",
              $metadata: deserializeMetadata(parsedOutput)
          };
          data = parsedOutput.body;
          return [2 /*return*/, contents];
      });
  }); };
  var serializeAws_restXmlAbortIncompleteMultipartUpload = function (input, context) {
      var bodyNode = new __XmlNode("AbortIncompleteMultipartUpload");
      if (input.DaysAfterInitiation !== undefined) {
          bodyNode.addChildNode(new __XmlNode("DaysAfterInitiation")
              .addChildNode(new __XmlText(String(input.DaysAfterInitiation)))
              .withName("DaysAfterInitiation"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlAccelerateConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("AccelerateConfiguration");
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("BucketAccelerateStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlAccessControlPolicy = function (input, context) {
      var bodyNode = new __XmlNode("AccessControlPolicy");
      if (input.Grants !== undefined) {
          var nodes = serializeAws_restXmlGrants(input.Grants, context);
          var containerNode_1 = new __XmlNode("AccessControlList");
          nodes.map(function (node) {
              containerNode_1.addChildNode(node);
          });
          bodyNode.addChildNode(containerNode_1);
      }
      if (input.Owner !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlOwner(input.Owner, context).withName("Owner"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlAccessControlTranslation = function (input, context) {
      var bodyNode = new __XmlNode("AccessControlTranslation");
      if (input.Owner !== undefined) {
          bodyNode.addChildNode(new __XmlNode("OwnerOverride")
              .addChildNode(new __XmlText(input.Owner))
              .withName("Owner"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlAllowedHeaders = function (input, context) {
      var e_1, _a;
      var collectedNodes = [];
      try {
          for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
              var entry = input_1_1.value;
              var node = new __XmlNode("AllowedHeader").addChildNode(new __XmlText(entry));
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_1_1) { e_1 = { error: e_1_1 }; }
      finally {
          try {
              if (input_1_1 && !input_1_1.done && (_a = input_1.return)) _a.call(input_1);
          }
          finally { if (e_1) throw e_1.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlAllowedMethods = function (input, context) {
      var e_2, _a;
      var collectedNodes = [];
      try {
          for (var input_2 = __values(input), input_2_1 = input_2.next(); !input_2_1.done; input_2_1 = input_2.next()) {
              var entry = input_2_1.value;
              var node = new __XmlNode("AllowedMethod").addChildNode(new __XmlText(entry));
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_2_1) { e_2 = { error: e_2_1 }; }
      finally {
          try {
              if (input_2_1 && !input_2_1.done && (_a = input_2.return)) _a.call(input_2);
          }
          finally { if (e_2) throw e_2.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlAllowedOrigins = function (input, context) {
      var e_3, _a;
      var collectedNodes = [];
      try {
          for (var input_3 = __values(input), input_3_1 = input_3.next(); !input_3_1.done; input_3_1 = input_3.next()) {
              var entry = input_3_1.value;
              var node = new __XmlNode("AllowedOrigin").addChildNode(new __XmlText(entry));
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_3_1) { e_3 = { error: e_3_1 }; }
      finally {
          try {
              if (input_3_1 && !input_3_1.done && (_a = input_3.return)) _a.call(input_3);
          }
          finally { if (e_3) throw e_3.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlAnalyticsAndOperator = function (input, context) {
      var bodyNode = new __XmlNode("AnalyticsAndOperator");
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Tags !== undefined) {
          var nodes = serializeAws_restXmlTagSet(input.Tags, context);
          nodes.map(function (node) {
              node = node.withName("Tag");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlAnalyticsConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("AnalyticsConfiguration");
      if (input.Filter !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlAnalyticsFilter(input.Filter, context).withName("Filter"));
      }
      if (input.Id !== undefined) {
          bodyNode.addChildNode(new __XmlNode("AnalyticsId")
              .addChildNode(new __XmlText(input.Id))
              .withName("Id"));
      }
      if (input.StorageClassAnalysis !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlStorageClassAnalysis(input.StorageClassAnalysis, context).withName("StorageClassAnalysis"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlAnalyticsExportDestination = function (input, context) {
      var bodyNode = new __XmlNode("AnalyticsExportDestination");
      if (input.S3BucketDestination !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlAnalyticsS3BucketDestination(input.S3BucketDestination, context).withName("S3BucketDestination"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlAnalyticsFilter = function (input, context) {
      var bodyNode = new __XmlNode("AnalyticsFilter");
      if (input.And !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlAnalyticsAndOperator(input.And, context).withName("And"));
      }
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Tag !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlTag(input.Tag, context).withName("Tag"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlAnalyticsS3BucketDestination = function (input, context) {
      var bodyNode = new __XmlNode("AnalyticsS3BucketDestination");
      if (input.Bucket !== undefined) {
          bodyNode.addChildNode(new __XmlNode("BucketName")
              .addChildNode(new __XmlText(input.Bucket))
              .withName("Bucket"));
      }
      if (input.BucketAccountId !== undefined) {
          bodyNode.addChildNode(new __XmlNode("AccountId")
              .addChildNode(new __XmlText(input.BucketAccountId))
              .withName("BucketAccountId"));
      }
      if (input.Format !== undefined) {
          bodyNode.addChildNode(new __XmlNode("AnalyticsS3ExportFileFormat")
              .addChildNode(new __XmlText(input.Format))
              .withName("Format"));
      }
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlBucketLifecycleConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("BucketLifecycleConfiguration");
      if (input.Rules !== undefined) {
          var nodes = serializeAws_restXmlLifecycleRules(input.Rules, context);
          nodes.map(function (node) {
              node = node.withName("Rule");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlBucketLoggingStatus = function (input, context) {
      var bodyNode = new __XmlNode("BucketLoggingStatus");
      if (input.LoggingEnabled !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlLoggingEnabled(input.LoggingEnabled, context).withName("LoggingEnabled"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlCORSConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("CORSConfiguration");
      if (input.CORSRules !== undefined) {
          var nodes = serializeAws_restXmlCORSRules(input.CORSRules, context);
          nodes.map(function (node) {
              node = node.withName("CORSRule");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlCORSRule = function (input, context) {
      var bodyNode = new __XmlNode("CORSRule");
      if (input.AllowedHeaders !== undefined) {
          var nodes = serializeAws_restXmlAllowedHeaders(input.AllowedHeaders, context);
          nodes.map(function (node) {
              node = node.withName("AllowedHeader");
              bodyNode.addChildNode(node);
          });
      }
      if (input.AllowedMethods !== undefined) {
          var nodes = serializeAws_restXmlAllowedMethods(input.AllowedMethods, context);
          nodes.map(function (node) {
              node = node.withName("AllowedMethod");
              bodyNode.addChildNode(node);
          });
      }
      if (input.AllowedOrigins !== undefined) {
          var nodes = serializeAws_restXmlAllowedOrigins(input.AllowedOrigins, context);
          nodes.map(function (node) {
              node = node.withName("AllowedOrigin");
              bodyNode.addChildNode(node);
          });
      }
      if (input.ExposeHeaders !== undefined) {
          var nodes = serializeAws_restXmlExposeHeaders(input.ExposeHeaders, context);
          nodes.map(function (node) {
              node = node.withName("ExposeHeader");
              bodyNode.addChildNode(node);
          });
      }
      if (input.MaxAgeSeconds !== undefined) {
          bodyNode.addChildNode(new __XmlNode("MaxAgeSeconds")
              .addChildNode(new __XmlText(String(input.MaxAgeSeconds)))
              .withName("MaxAgeSeconds"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlCORSRules = function (input, context) {
      var e_4, _a;
      var collectedNodes = [];
      try {
          for (var input_4 = __values(input), input_4_1 = input_4.next(); !input_4_1.done; input_4_1 = input_4.next()) {
              var entry = input_4_1.value;
              var node = serializeAws_restXmlCORSRule(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_4_1) { e_4 = { error: e_4_1 }; }
      finally {
          try {
              if (input_4_1 && !input_4_1.done && (_a = input_4.return)) _a.call(input_4);
          }
          finally { if (e_4) throw e_4.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlCSVInput = function (input, context) {
      var bodyNode = new __XmlNode("CSVInput");
      if (input.AllowQuotedRecordDelimiter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("AllowQuotedRecordDelimiter")
              .addChildNode(new __XmlText(String(input.AllowQuotedRecordDelimiter)))
              .withName("AllowQuotedRecordDelimiter"));
      }
      if (input.Comments !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Comments")
              .addChildNode(new __XmlText(input.Comments))
              .withName("Comments"));
      }
      if (input.FieldDelimiter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("FieldDelimiter")
              .addChildNode(new __XmlText(input.FieldDelimiter))
              .withName("FieldDelimiter"));
      }
      if (input.FileHeaderInfo !== undefined) {
          bodyNode.addChildNode(new __XmlNode("FileHeaderInfo")
              .addChildNode(new __XmlText(input.FileHeaderInfo))
              .withName("FileHeaderInfo"));
      }
      if (input.QuoteCharacter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("QuoteCharacter")
              .addChildNode(new __XmlText(input.QuoteCharacter))
              .withName("QuoteCharacter"));
      }
      if (input.QuoteEscapeCharacter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("QuoteEscapeCharacter")
              .addChildNode(new __XmlText(input.QuoteEscapeCharacter))
              .withName("QuoteEscapeCharacter"));
      }
      if (input.RecordDelimiter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("RecordDelimiter")
              .addChildNode(new __XmlText(input.RecordDelimiter))
              .withName("RecordDelimiter"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlCSVOutput = function (input, context) {
      var bodyNode = new __XmlNode("CSVOutput");
      if (input.FieldDelimiter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("FieldDelimiter")
              .addChildNode(new __XmlText(input.FieldDelimiter))
              .withName("FieldDelimiter"));
      }
      if (input.QuoteCharacter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("QuoteCharacter")
              .addChildNode(new __XmlText(input.QuoteCharacter))
              .withName("QuoteCharacter"));
      }
      if (input.QuoteEscapeCharacter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("QuoteEscapeCharacter")
              .addChildNode(new __XmlText(input.QuoteEscapeCharacter))
              .withName("QuoteEscapeCharacter"));
      }
      if (input.QuoteFields !== undefined) {
          bodyNode.addChildNode(new __XmlNode("QuoteFields")
              .addChildNode(new __XmlText(input.QuoteFields))
              .withName("QuoteFields"));
      }
      if (input.RecordDelimiter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("RecordDelimiter")
              .addChildNode(new __XmlText(input.RecordDelimiter))
              .withName("RecordDelimiter"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlCompletedMultipartUpload = function (input, context) {
      var bodyNode = new __XmlNode("CompletedMultipartUpload");
      if (input.Parts !== undefined) {
          var nodes = serializeAws_restXmlCompletedPartList(input.Parts, context);
          nodes.map(function (node) {
              node = node.withName("Part");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlCompletedPart = function (input, context) {
      var bodyNode = new __XmlNode("CompletedPart");
      if (input.ETag !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ETag")
              .addChildNode(new __XmlText(input.ETag))
              .withName("ETag"));
      }
      if (input.PartNumber !== undefined) {
          bodyNode.addChildNode(new __XmlNode("PartNumber")
              .addChildNode(new __XmlText(String(input.PartNumber)))
              .withName("PartNumber"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlCompletedPartList = function (input, context) {
      var e_5, _a;
      var collectedNodes = [];
      try {
          for (var input_5 = __values(input), input_5_1 = input_5.next(); !input_5_1.done; input_5_1 = input_5.next()) {
              var entry = input_5_1.value;
              var node = serializeAws_restXmlCompletedPart(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_5_1) { e_5 = { error: e_5_1 }; }
      finally {
          try {
              if (input_5_1 && !input_5_1.done && (_a = input_5.return)) _a.call(input_5);
          }
          finally { if (e_5) throw e_5.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlCondition = function (input, context) {
      var bodyNode = new __XmlNode("Condition");
      if (input.HttpErrorCodeReturnedEquals !== undefined) {
          bodyNode.addChildNode(new __XmlNode("HttpErrorCodeReturnedEquals")
              .addChildNode(new __XmlText(input.HttpErrorCodeReturnedEquals))
              .withName("HttpErrorCodeReturnedEquals"));
      }
      if (input.KeyPrefixEquals !== undefined) {
          bodyNode.addChildNode(new __XmlNode("KeyPrefixEquals")
              .addChildNode(new __XmlText(input.KeyPrefixEquals))
              .withName("KeyPrefixEquals"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlCreateBucketConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("CreateBucketConfiguration");
      if (input.LocationConstraint !== undefined) {
          bodyNode.addChildNode(new __XmlNode("BucketLocationConstraint")
              .addChildNode(new __XmlText(input.LocationConstraint))
              .withName("LocationConstraint"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlDefaultRetention = function (input, context) {
      var bodyNode = new __XmlNode("DefaultRetention");
      if (input.Days !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Days")
              .addChildNode(new __XmlText(String(input.Days)))
              .withName("Days"));
      }
      if (input.Mode !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ObjectLockRetentionMode")
              .addChildNode(new __XmlText(input.Mode))
              .withName("Mode"));
      }
      if (input.Years !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Years")
              .addChildNode(new __XmlText(String(input.Years)))
              .withName("Years"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlDelete = function (input, context) {
      var bodyNode = new __XmlNode("Delete");
      if (input.Objects !== undefined) {
          var nodes = serializeAws_restXmlObjectIdentifierList(input.Objects, context);
          nodes.map(function (node) {
              node = node.withName("Object");
              bodyNode.addChildNode(node);
          });
      }
      if (input.Quiet !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Quiet")
              .addChildNode(new __XmlText(String(input.Quiet)))
              .withName("Quiet"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlDeleteMarkerReplication = function (input, context) {
      var bodyNode = new __XmlNode("DeleteMarkerReplication");
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("DeleteMarkerReplicationStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlDestination = function (input, context) {
      var bodyNode = new __XmlNode("Destination");
      if (input.AccessControlTranslation !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlAccessControlTranslation(input.AccessControlTranslation, context).withName("AccessControlTranslation"));
      }
      if (input.Account !== undefined) {
          bodyNode.addChildNode(new __XmlNode("AccountId")
              .addChildNode(new __XmlText(input.Account))
              .withName("Account"));
      }
      if (input.Bucket !== undefined) {
          bodyNode.addChildNode(new __XmlNode("BucketName")
              .addChildNode(new __XmlText(input.Bucket))
              .withName("Bucket"));
      }
      if (input.EncryptionConfiguration !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlEncryptionConfiguration(input.EncryptionConfiguration, context).withName("EncryptionConfiguration"));
      }
      if (input.Metrics !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlMetrics(input.Metrics, context).withName("Metrics"));
      }
      if (input.ReplicationTime !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlReplicationTime(input.ReplicationTime, context).withName("ReplicationTime"));
      }
      if (input.StorageClass !== undefined) {
          bodyNode.addChildNode(new __XmlNode("StorageClass")
              .addChildNode(new __XmlText(input.StorageClass))
              .withName("StorageClass"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlEncryption = function (input, context) {
      var bodyNode = new __XmlNode("Encryption");
      if (input.EncryptionType !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ServerSideEncryption")
              .addChildNode(new __XmlText(input.EncryptionType))
              .withName("EncryptionType"));
      }
      if (input.KMSContext !== undefined) {
          bodyNode.addChildNode(new __XmlNode("KMSContext")
              .addChildNode(new __XmlText(input.KMSContext))
              .withName("KMSContext"));
      }
      if (input.KMSKeyId !== undefined) {
          bodyNode.addChildNode(new __XmlNode("SSEKMSKeyId")
              .addChildNode(new __XmlText(input.KMSKeyId))
              .withName("KMSKeyId"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlEncryptionConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("EncryptionConfiguration");
      if (input.ReplicaKmsKeyID !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ReplicaKmsKeyID")
              .addChildNode(new __XmlText(input.ReplicaKmsKeyID))
              .withName("ReplicaKmsKeyID"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlErrorDocument = function (input, context) {
      var bodyNode = new __XmlNode("ErrorDocument");
      if (input.Key !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ObjectKey")
              .addChildNode(new __XmlText(input.Key))
              .withName("Key"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlEventList = function (input, context) {
      var e_6, _a;
      var collectedNodes = [];
      try {
          for (var input_6 = __values(input), input_6_1 = input_6.next(); !input_6_1.done; input_6_1 = input_6.next()) {
              var entry = input_6_1.value;
              var node = new __XmlNode("Event").addChildNode(new __XmlText(entry));
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_6_1) { e_6 = { error: e_6_1 }; }
      finally {
          try {
              if (input_6_1 && !input_6_1.done && (_a = input_6.return)) _a.call(input_6);
          }
          finally { if (e_6) throw e_6.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlExistingObjectReplication = function (input, context) {
      var bodyNode = new __XmlNode("ExistingObjectReplication");
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ExistingObjectReplicationStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlExposeHeaders = function (input, context) {
      var e_7, _a;
      var collectedNodes = [];
      try {
          for (var input_7 = __values(input), input_7_1 = input_7.next(); !input_7_1.done; input_7_1 = input_7.next()) {
              var entry = input_7_1.value;
              var node = new __XmlNode("ExposeHeader").addChildNode(new __XmlText(entry));
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_7_1) { e_7 = { error: e_7_1 }; }
      finally {
          try {
              if (input_7_1 && !input_7_1.done && (_a = input_7.return)) _a.call(input_7);
          }
          finally { if (e_7) throw e_7.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlFilterRule = function (input, context) {
      var bodyNode = new __XmlNode("FilterRule");
      if (input.Name !== undefined) {
          bodyNode.addChildNode(new __XmlNode("FilterRuleName")
              .addChildNode(new __XmlText(input.Name))
              .withName("Name"));
      }
      if (input.Value !== undefined) {
          bodyNode.addChildNode(new __XmlNode("FilterRuleValue")
              .addChildNode(new __XmlText(input.Value))
              .withName("Value"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlFilterRuleList = function (input, context) {
      var e_8, _a;
      var collectedNodes = [];
      try {
          for (var input_8 = __values(input), input_8_1 = input_8.next(); !input_8_1.done; input_8_1 = input_8.next()) {
              var entry = input_8_1.value;
              var node = serializeAws_restXmlFilterRule(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_8_1) { e_8 = { error: e_8_1 }; }
      finally {
          try {
              if (input_8_1 && !input_8_1.done && (_a = input_8.return)) _a.call(input_8);
          }
          finally { if (e_8) throw e_8.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlGlacierJobParameters = function (input, context) {
      var bodyNode = new __XmlNode("GlacierJobParameters");
      if (input.Tier !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Tier")
              .addChildNode(new __XmlText(input.Tier))
              .withName("Tier"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlGrant = function (input, context) {
      var bodyNode = new __XmlNode("Grant");
      if (input.Grantee !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlGrantee(input.Grantee, context).withName("Grantee"));
      }
      if (input.Permission !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Permission")
              .addChildNode(new __XmlText(input.Permission))
              .withName("Permission"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlGrantee = function (input, context) {
      var bodyNode = new __XmlNode("Grantee");
      bodyNode.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      if (input.DisplayName !== undefined) {
          bodyNode.addChildNode(new __XmlNode("DisplayName")
              .addChildNode(new __XmlText(input.DisplayName))
              .withName("DisplayName"));
      }
      if (input.EmailAddress !== undefined) {
          bodyNode.addChildNode(new __XmlNode("EmailAddress")
              .addChildNode(new __XmlText(input.EmailAddress))
              .withName("EmailAddress"));
      }
      if (input.ID !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ID").addChildNode(new __XmlText(input.ID)).withName("ID"));
      }
      if (input.Type !== undefined) {
          bodyNode.addAttribute("xsi:type", input.Type);
      }
      if (input.URI !== undefined) {
          bodyNode.addChildNode(new __XmlNode("URI")
              .addChildNode(new __XmlText(input.URI))
              .withName("URI"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlGrants = function (input, context) {
      var e_9, _a;
      var collectedNodes = [];
      try {
          for (var input_9 = __values(input), input_9_1 = input_9.next(); !input_9_1.done; input_9_1 = input_9.next()) {
              var entry = input_9_1.value;
              var node = serializeAws_restXmlGrant(entry, context);
              collectedNodes.push(node.withName("Grant"));
          }
      }
      catch (e_9_1) { e_9 = { error: e_9_1 }; }
      finally {
          try {
              if (input_9_1 && !input_9_1.done && (_a = input_9.return)) _a.call(input_9);
          }
          finally { if (e_9) throw e_9.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlIndexDocument = function (input, context) {
      var bodyNode = new __XmlNode("IndexDocument");
      if (input.Suffix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Suffix")
              .addChildNode(new __XmlText(input.Suffix))
              .withName("Suffix"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlInputSerialization = function (input, context) {
      var bodyNode = new __XmlNode("InputSerialization");
      if (input.CSV !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlCSVInput(input.CSV, context).withName("CSV"));
      }
      if (input.CompressionType !== undefined) {
          bodyNode.addChildNode(new __XmlNode("CompressionType")
              .addChildNode(new __XmlText(input.CompressionType))
              .withName("CompressionType"));
      }
      if (input.JSON !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlJSONInput(input.JSON, context).withName("JSON"));
      }
      if (input.Parquet !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlParquetInput(input.Parquet, context).withName("Parquet"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlInventoryConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("InventoryConfiguration");
      if (input.Destination !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlInventoryDestination(input.Destination, context).withName("Destination"));
      }
      if (input.Filter !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlInventoryFilter(input.Filter, context).withName("Filter"));
      }
      if (input.Id !== undefined) {
          bodyNode.addChildNode(new __XmlNode("InventoryId")
              .addChildNode(new __XmlText(input.Id))
              .withName("Id"));
      }
      if (input.IncludedObjectVersions !== undefined) {
          bodyNode.addChildNode(new __XmlNode("InventoryIncludedObjectVersions")
              .addChildNode(new __XmlText(input.IncludedObjectVersions))
              .withName("IncludedObjectVersions"));
      }
      if (input.IsEnabled !== undefined) {
          bodyNode.addChildNode(new __XmlNode("IsEnabled")
              .addChildNode(new __XmlText(String(input.IsEnabled)))
              .withName("IsEnabled"));
      }
      if (input.OptionalFields !== undefined) {
          var nodes = serializeAws_restXmlInventoryOptionalFields(input.OptionalFields, context);
          var containerNode_2 = new __XmlNode("OptionalFields");
          nodes.map(function (node) {
              containerNode_2.addChildNode(node);
          });
          bodyNode.addChildNode(containerNode_2);
      }
      if (input.Schedule !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlInventorySchedule(input.Schedule, context).withName("Schedule"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlInventoryDestination = function (input, context) {
      var bodyNode = new __XmlNode("InventoryDestination");
      if (input.S3BucketDestination !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlInventoryS3BucketDestination(input.S3BucketDestination, context).withName("S3BucketDestination"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlInventoryEncryption = function (input, context) {
      var bodyNode = new __XmlNode("InventoryEncryption");
      if (input.SSEKMS !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlSSEKMS(input.SSEKMS, context).withName("SSE-KMS"));
      }
      if (input.SSES3 !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlSSES3(input.SSES3, context).withName("SSE-S3"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlInventoryFilter = function (input, context) {
      var bodyNode = new __XmlNode("InventoryFilter");
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlInventoryOptionalFields = function (input, context) {
      var e_10, _a;
      var collectedNodes = [];
      try {
          for (var input_10 = __values(input), input_10_1 = input_10.next(); !input_10_1.done; input_10_1 = input_10.next()) {
              var entry = input_10_1.value;
              var node = new __XmlNode("InventoryOptionalField").addChildNode(new __XmlText(entry));
              collectedNodes.push(node.withName("Field"));
          }
      }
      catch (e_10_1) { e_10 = { error: e_10_1 }; }
      finally {
          try {
              if (input_10_1 && !input_10_1.done && (_a = input_10.return)) _a.call(input_10);
          }
          finally { if (e_10) throw e_10.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlInventoryS3BucketDestination = function (input, context) {
      var bodyNode = new __XmlNode("InventoryS3BucketDestination");
      if (input.AccountId !== undefined) {
          bodyNode.addChildNode(new __XmlNode("AccountId")
              .addChildNode(new __XmlText(input.AccountId))
              .withName("AccountId"));
      }
      if (input.Bucket !== undefined) {
          bodyNode.addChildNode(new __XmlNode("BucketName")
              .addChildNode(new __XmlText(input.Bucket))
              .withName("Bucket"));
      }
      if (input.Encryption !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlInventoryEncryption(input.Encryption, context).withName("Encryption"));
      }
      if (input.Format !== undefined) {
          bodyNode.addChildNode(new __XmlNode("InventoryFormat")
              .addChildNode(new __XmlText(input.Format))
              .withName("Format"));
      }
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlInventorySchedule = function (input, context) {
      var bodyNode = new __XmlNode("InventorySchedule");
      if (input.Frequency !== undefined) {
          bodyNode.addChildNode(new __XmlNode("InventoryFrequency")
              .addChildNode(new __XmlText(input.Frequency))
              .withName("Frequency"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlJSONInput = function (input, context) {
      var bodyNode = new __XmlNode("JSONInput");
      if (input.Type !== undefined) {
          bodyNode.addChildNode(new __XmlNode("JSONType")
              .addChildNode(new __XmlText(input.Type))
              .withName("Type"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlJSONOutput = function (input, context) {
      var bodyNode = new __XmlNode("JSONOutput");
      if (input.RecordDelimiter !== undefined) {
          bodyNode.addChildNode(new __XmlNode("RecordDelimiter")
              .addChildNode(new __XmlText(input.RecordDelimiter))
              .withName("RecordDelimiter"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlLambdaFunctionConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("LambdaFunctionConfiguration");
      if (input.Events !== undefined) {
          var nodes = serializeAws_restXmlEventList(input.Events, context);
          nodes.map(function (node) {
              node = node.withName("Event");
              bodyNode.addChildNode(node);
          });
      }
      if (input.Filter !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlNotificationConfigurationFilter(input.Filter, context).withName("Filter"));
      }
      if (input.Id !== undefined) {
          bodyNode.addChildNode(new __XmlNode("NotificationId")
              .addChildNode(new __XmlText(input.Id))
              .withName("Id"));
      }
      if (input.LambdaFunctionArn !== undefined) {
          bodyNode.addChildNode(new __XmlNode("LambdaFunctionArn")
              .addChildNode(new __XmlText(input.LambdaFunctionArn))
              .withName("CloudFunction"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlLambdaFunctionConfigurationList = function (input, context) {
      var e_11, _a;
      var collectedNodes = [];
      try {
          for (var input_11 = __values(input), input_11_1 = input_11.next(); !input_11_1.done; input_11_1 = input_11.next()) {
              var entry = input_11_1.value;
              var node = serializeAws_restXmlLambdaFunctionConfiguration(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_11_1) { e_11 = { error: e_11_1 }; }
      finally {
          try {
              if (input_11_1 && !input_11_1.done && (_a = input_11.return)) _a.call(input_11);
          }
          finally { if (e_11) throw e_11.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlLifecycleExpiration = function (input, context) {
      var bodyNode = new __XmlNode("LifecycleExpiration");
      if (input.Date !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Date")
              .addChildNode(new __XmlText(input.Date.toISOString().split(".")[0] + "Z"))
              .withName("Date"));
      }
      if (input.Days !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Days")
              .addChildNode(new __XmlText(String(input.Days)))
              .withName("Days"));
      }
      if (input.ExpiredObjectDeleteMarker !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ExpiredObjectDeleteMarker")
              .addChildNode(new __XmlText(String(input.ExpiredObjectDeleteMarker)))
              .withName("ExpiredObjectDeleteMarker"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlLifecycleRule = function (input, context) {
      var bodyNode = new __XmlNode("LifecycleRule");
      if (input.AbortIncompleteMultipartUpload !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlAbortIncompleteMultipartUpload(input.AbortIncompleteMultipartUpload, context).withName("AbortIncompleteMultipartUpload"));
      }
      if (input.Expiration !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlLifecycleExpiration(input.Expiration, context).withName("Expiration"));
      }
      if (input.Filter !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlLifecycleRuleFilter(input.Filter, context).withName("Filter"));
      }
      if (input.ID !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ID").addChildNode(new __XmlText(input.ID)).withName("ID"));
      }
      if (input.NoncurrentVersionExpiration !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlNoncurrentVersionExpiration(input.NoncurrentVersionExpiration, context).withName("NoncurrentVersionExpiration"));
      }
      if (input.NoncurrentVersionTransitions !== undefined) {
          var nodes = serializeAws_restXmlNoncurrentVersionTransitionList(input.NoncurrentVersionTransitions, context);
          nodes.map(function (node) {
              node = node.withName("NoncurrentVersionTransition");
              bodyNode.addChildNode(node);
          });
      }
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ExpirationStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      if (input.Transitions !== undefined) {
          var nodes = serializeAws_restXmlTransitionList(input.Transitions, context);
          nodes.map(function (node) {
              node = node.withName("Transition");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlLifecycleRuleAndOperator = function (input, context) {
      var bodyNode = new __XmlNode("LifecycleRuleAndOperator");
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Tags !== undefined) {
          var nodes = serializeAws_restXmlTagSet(input.Tags, context);
          nodes.map(function (node) {
              node = node.withName("Tag");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlLifecycleRuleFilter = function (input, context) {
      var bodyNode = new __XmlNode("LifecycleRuleFilter");
      if (input.And !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlLifecycleRuleAndOperator(input.And, context).withName("And"));
      }
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Tag !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlTag(input.Tag, context).withName("Tag"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlLifecycleRules = function (input, context) {
      var e_12, _a;
      var collectedNodes = [];
      try {
          for (var input_12 = __values(input), input_12_1 = input_12.next(); !input_12_1.done; input_12_1 = input_12.next()) {
              var entry = input_12_1.value;
              var node = serializeAws_restXmlLifecycleRule(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_12_1) { e_12 = { error: e_12_1 }; }
      finally {
          try {
              if (input_12_1 && !input_12_1.done && (_a = input_12.return)) _a.call(input_12);
          }
          finally { if (e_12) throw e_12.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlLoggingEnabled = function (input, context) {
      var bodyNode = new __XmlNode("LoggingEnabled");
      if (input.TargetBucket !== undefined) {
          bodyNode.addChildNode(new __XmlNode("TargetBucket")
              .addChildNode(new __XmlText(input.TargetBucket))
              .withName("TargetBucket"));
      }
      if (input.TargetGrants !== undefined) {
          var nodes = serializeAws_restXmlTargetGrants(input.TargetGrants, context);
          var containerNode_3 = new __XmlNode("TargetGrants");
          nodes.map(function (node) {
              containerNode_3.addChildNode(node);
          });
          bodyNode.addChildNode(containerNode_3);
      }
      if (input.TargetPrefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("TargetPrefix")
              .addChildNode(new __XmlText(input.TargetPrefix))
              .withName("TargetPrefix"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlMetadataEntry = function (input, context) {
      var bodyNode = new __XmlNode("MetadataEntry");
      if (input.Name !== undefined) {
          bodyNode.addChildNode(new __XmlNode("MetadataKey")
              .addChildNode(new __XmlText(input.Name))
              .withName("Name"));
      }
      if (input.Value !== undefined) {
          bodyNode.addChildNode(new __XmlNode("MetadataValue")
              .addChildNode(new __XmlText(input.Value))
              .withName("Value"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlMetrics = function (input, context) {
      var bodyNode = new __XmlNode("Metrics");
      if (input.EventThreshold !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlReplicationTimeValue(input.EventThreshold, context).withName("EventThreshold"));
      }
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("MetricsStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlMetricsAndOperator = function (input, context) {
      var bodyNode = new __XmlNode("MetricsAndOperator");
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Tags !== undefined) {
          var nodes = serializeAws_restXmlTagSet(input.Tags, context);
          nodes.map(function (node) {
              node = node.withName("Tag");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlMetricsConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("MetricsConfiguration");
      if (input.Filter !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlMetricsFilter(input.Filter, context).withName("Filter"));
      }
      if (input.Id !== undefined) {
          bodyNode.addChildNode(new __XmlNode("MetricsId")
              .addChildNode(new __XmlText(input.Id))
              .withName("Id"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlMetricsFilter = function (input, context) {
      var bodyNode = new __XmlNode("MetricsFilter");
      if (input.And !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlMetricsAndOperator(input.And, context).withName("And"));
      }
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Tag !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlTag(input.Tag, context).withName("Tag"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlNoncurrentVersionExpiration = function (input, context) {
      var bodyNode = new __XmlNode("NoncurrentVersionExpiration");
      if (input.NoncurrentDays !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Days")
              .addChildNode(new __XmlText(String(input.NoncurrentDays)))
              .withName("NoncurrentDays"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlNoncurrentVersionTransition = function (input, context) {
      var bodyNode = new __XmlNode("NoncurrentVersionTransition");
      if (input.NoncurrentDays !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Days")
              .addChildNode(new __XmlText(String(input.NoncurrentDays)))
              .withName("NoncurrentDays"));
      }
      if (input.StorageClass !== undefined) {
          bodyNode.addChildNode(new __XmlNode("TransitionStorageClass")
              .addChildNode(new __XmlText(input.StorageClass))
              .withName("StorageClass"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlNoncurrentVersionTransitionList = function (input, context) {
      var e_13, _a;
      var collectedNodes = [];
      try {
          for (var input_13 = __values(input), input_13_1 = input_13.next(); !input_13_1.done; input_13_1 = input_13.next()) {
              var entry = input_13_1.value;
              var node = serializeAws_restXmlNoncurrentVersionTransition(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_13_1) { e_13 = { error: e_13_1 }; }
      finally {
          try {
              if (input_13_1 && !input_13_1.done && (_a = input_13.return)) _a.call(input_13);
          }
          finally { if (e_13) throw e_13.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlNotificationConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("NotificationConfiguration");
      if (input.LambdaFunctionConfigurations !== undefined) {
          var nodes = serializeAws_restXmlLambdaFunctionConfigurationList(input.LambdaFunctionConfigurations, context);
          nodes.map(function (node) {
              node = node.withName("CloudFunctionConfiguration");
              bodyNode.addChildNode(node);
          });
      }
      if (input.QueueConfigurations !== undefined) {
          var nodes = serializeAws_restXmlQueueConfigurationList(input.QueueConfigurations, context);
          nodes.map(function (node) {
              node = node.withName("QueueConfiguration");
              bodyNode.addChildNode(node);
          });
      }
      if (input.TopicConfigurations !== undefined) {
          var nodes = serializeAws_restXmlTopicConfigurationList(input.TopicConfigurations, context);
          nodes.map(function (node) {
              node = node.withName("TopicConfiguration");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlNotificationConfigurationFilter = function (input, context) {
      var bodyNode = new __XmlNode("NotificationConfigurationFilter");
      if (input.Key !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlS3KeyFilter(input.Key, context).withName("S3Key"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlObjectIdentifier = function (input, context) {
      var bodyNode = new __XmlNode("ObjectIdentifier");
      if (input.Key !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ObjectKey")
              .addChildNode(new __XmlText(input.Key))
              .withName("Key"));
      }
      if (input.VersionId !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ObjectVersionId")
              .addChildNode(new __XmlText(input.VersionId))
              .withName("VersionId"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlObjectIdentifierList = function (input, context) {
      var e_14, _a;
      var collectedNodes = [];
      try {
          for (var input_14 = __values(input), input_14_1 = input_14.next(); !input_14_1.done; input_14_1 = input_14.next()) {
              var entry = input_14_1.value;
              var node = serializeAws_restXmlObjectIdentifier(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_14_1) { e_14 = { error: e_14_1 }; }
      finally {
          try {
              if (input_14_1 && !input_14_1.done && (_a = input_14.return)) _a.call(input_14);
          }
          finally { if (e_14) throw e_14.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlObjectLockConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("ObjectLockConfiguration");
      if (input.ObjectLockEnabled !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ObjectLockEnabled")
              .addChildNode(new __XmlText(input.ObjectLockEnabled))
              .withName("ObjectLockEnabled"));
      }
      if (input.Rule !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlObjectLockRule(input.Rule, context).withName("Rule"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlObjectLockLegalHold = function (input, context) {
      var bodyNode = new __XmlNode("ObjectLockLegalHold");
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ObjectLockLegalHoldStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlObjectLockRetention = function (input, context) {
      var bodyNode = new __XmlNode("ObjectLockRetention");
      if (input.Mode !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ObjectLockRetentionMode")
              .addChildNode(new __XmlText(input.Mode))
              .withName("Mode"));
      }
      if (input.RetainUntilDate !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Date")
              .addChildNode(new __XmlText(input.RetainUntilDate.toISOString().split(".")[0] + "Z"))
              .withName("RetainUntilDate"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlObjectLockRule = function (input, context) {
      var bodyNode = new __XmlNode("ObjectLockRule");
      if (input.DefaultRetention !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlDefaultRetention(input.DefaultRetention, context).withName("DefaultRetention"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlOutputLocation = function (input, context) {
      var bodyNode = new __XmlNode("OutputLocation");
      if (input.S3 !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlS3Location(input.S3, context).withName("S3"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlOutputSerialization = function (input, context) {
      var bodyNode = new __XmlNode("OutputSerialization");
      if (input.CSV !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlCSVOutput(input.CSV, context).withName("CSV"));
      }
      if (input.JSON !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlJSONOutput(input.JSON, context).withName("JSON"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlOwner = function (input, context) {
      var bodyNode = new __XmlNode("Owner");
      if (input.DisplayName !== undefined) {
          bodyNode.addChildNode(new __XmlNode("DisplayName")
              .addChildNode(new __XmlText(input.DisplayName))
              .withName("DisplayName"));
      }
      if (input.ID !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ID").addChildNode(new __XmlText(input.ID)).withName("ID"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlParquetInput = function (input, context) {
      var bodyNode = new __XmlNode("ParquetInput");
      return bodyNode;
  };
  var serializeAws_restXmlPublicAccessBlockConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("PublicAccessBlockConfiguration");
      if (input.BlockPublicAcls !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Setting")
              .addChildNode(new __XmlText(String(input.BlockPublicAcls)))
              .withName("BlockPublicAcls"));
      }
      if (input.BlockPublicPolicy !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Setting")
              .addChildNode(new __XmlText(String(input.BlockPublicPolicy)))
              .withName("BlockPublicPolicy"));
      }
      if (input.IgnorePublicAcls !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Setting")
              .addChildNode(new __XmlText(String(input.IgnorePublicAcls)))
              .withName("IgnorePublicAcls"));
      }
      if (input.RestrictPublicBuckets !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Setting")
              .addChildNode(new __XmlText(String(input.RestrictPublicBuckets)))
              .withName("RestrictPublicBuckets"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlQueueConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("QueueConfiguration");
      if (input.Events !== undefined) {
          var nodes = serializeAws_restXmlEventList(input.Events, context);
          nodes.map(function (node) {
              node = node.withName("Event");
              bodyNode.addChildNode(node);
          });
      }
      if (input.Filter !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlNotificationConfigurationFilter(input.Filter, context).withName("Filter"));
      }
      if (input.Id !== undefined) {
          bodyNode.addChildNode(new __XmlNode("NotificationId")
              .addChildNode(new __XmlText(input.Id))
              .withName("Id"));
      }
      if (input.QueueArn !== undefined) {
          bodyNode.addChildNode(new __XmlNode("QueueArn")
              .addChildNode(new __XmlText(input.QueueArn))
              .withName("Queue"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlQueueConfigurationList = function (input, context) {
      var e_15, _a;
      var collectedNodes = [];
      try {
          for (var input_15 = __values(input), input_15_1 = input_15.next(); !input_15_1.done; input_15_1 = input_15.next()) {
              var entry = input_15_1.value;
              var node = serializeAws_restXmlQueueConfiguration(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_15_1) { e_15 = { error: e_15_1 }; }
      finally {
          try {
              if (input_15_1 && !input_15_1.done && (_a = input_15.return)) _a.call(input_15);
          }
          finally { if (e_15) throw e_15.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlRedirect = function (input, context) {
      var bodyNode = new __XmlNode("Redirect");
      if (input.HostName !== undefined) {
          bodyNode.addChildNode(new __XmlNode("HostName")
              .addChildNode(new __XmlText(input.HostName))
              .withName("HostName"));
      }
      if (input.HttpRedirectCode !== undefined) {
          bodyNode.addChildNode(new __XmlNode("HttpRedirectCode")
              .addChildNode(new __XmlText(input.HttpRedirectCode))
              .withName("HttpRedirectCode"));
      }
      if (input.Protocol !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Protocol")
              .addChildNode(new __XmlText(input.Protocol))
              .withName("Protocol"));
      }
      if (input.ReplaceKeyPrefixWith !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ReplaceKeyPrefixWith")
              .addChildNode(new __XmlText(input.ReplaceKeyPrefixWith))
              .withName("ReplaceKeyPrefixWith"));
      }
      if (input.ReplaceKeyWith !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ReplaceKeyWith")
              .addChildNode(new __XmlText(input.ReplaceKeyWith))
              .withName("ReplaceKeyWith"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlRedirectAllRequestsTo = function (input, context) {
      var bodyNode = new __XmlNode("RedirectAllRequestsTo");
      if (input.HostName !== undefined) {
          bodyNode.addChildNode(new __XmlNode("HostName")
              .addChildNode(new __XmlText(input.HostName))
              .withName("HostName"));
      }
      if (input.Protocol !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Protocol")
              .addChildNode(new __XmlText(input.Protocol))
              .withName("Protocol"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlReplicationConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("ReplicationConfiguration");
      if (input.Role !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Role")
              .addChildNode(new __XmlText(input.Role))
              .withName("Role"));
      }
      if (input.Rules !== undefined) {
          var nodes = serializeAws_restXmlReplicationRules(input.Rules, context);
          nodes.map(function (node) {
              node = node.withName("Rule");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlReplicationRule = function (input, context) {
      var bodyNode = new __XmlNode("ReplicationRule");
      if (input.DeleteMarkerReplication !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlDeleteMarkerReplication(input.DeleteMarkerReplication, context).withName("DeleteMarkerReplication"));
      }
      if (input.Destination !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlDestination(input.Destination, context).withName("Destination"));
      }
      if (input.ExistingObjectReplication !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlExistingObjectReplication(input.ExistingObjectReplication, context).withName("ExistingObjectReplication"));
      }
      if (input.Filter !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlReplicationRuleFilter(input.Filter, context).withName("Filter"));
      }
      if (input.ID !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ID").addChildNode(new __XmlText(input.ID)).withName("ID"));
      }
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Priority !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Priority")
              .addChildNode(new __XmlText(String(input.Priority)))
              .withName("Priority"));
      }
      if (input.SourceSelectionCriteria !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlSourceSelectionCriteria(input.SourceSelectionCriteria, context).withName("SourceSelectionCriteria"));
      }
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ReplicationRuleStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlReplicationRuleAndOperator = function (input, context) {
      var bodyNode = new __XmlNode("ReplicationRuleAndOperator");
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Tags !== undefined) {
          var nodes = serializeAws_restXmlTagSet(input.Tags, context);
          nodes.map(function (node) {
              node = node.withName("Tag");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlReplicationRuleFilter = function (input, context) {
      var bodyNode = new __XmlNode("ReplicationRuleFilter");
      if (input.And !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlReplicationRuleAndOperator(input.And, context).withName("And"));
      }
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Prefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.Tag !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlTag(input.Tag, context).withName("Tag"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlReplicationRules = function (input, context) {
      var e_16, _a;
      var collectedNodes = [];
      try {
          for (var input_16 = __values(input), input_16_1 = input_16.next(); !input_16_1.done; input_16_1 = input_16.next()) {
              var entry = input_16_1.value;
              var node = serializeAws_restXmlReplicationRule(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_16_1) { e_16 = { error: e_16_1 }; }
      finally {
          try {
              if (input_16_1 && !input_16_1.done && (_a = input_16.return)) _a.call(input_16);
          }
          finally { if (e_16) throw e_16.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlReplicationTime = function (input, context) {
      var bodyNode = new __XmlNode("ReplicationTime");
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ReplicationTimeStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      if (input.Time !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlReplicationTimeValue(input.Time, context).withName("Time"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlReplicationTimeValue = function (input, context) {
      var bodyNode = new __XmlNode("ReplicationTimeValue");
      if (input.Minutes !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Minutes")
              .addChildNode(new __XmlText(String(input.Minutes)))
              .withName("Minutes"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlRequestPaymentConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("RequestPaymentConfiguration");
      if (input.Payer !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Payer")
              .addChildNode(new __XmlText(input.Payer))
              .withName("Payer"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlRequestProgress = function (input, context) {
      var bodyNode = new __XmlNode("RequestProgress");
      if (input.Enabled !== undefined) {
          bodyNode.addChildNode(new __XmlNode("EnableRequestProgress")
              .addChildNode(new __XmlText(String(input.Enabled)))
              .withName("Enabled"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlRestoreRequest = function (input, context) {
      var bodyNode = new __XmlNode("RestoreRequest");
      if (input.Days !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Days")
              .addChildNode(new __XmlText(String(input.Days)))
              .withName("Days"));
      }
      if (input.Description !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Description")
              .addChildNode(new __XmlText(input.Description))
              .withName("Description"));
      }
      if (input.GlacierJobParameters !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlGlacierJobParameters(input.GlacierJobParameters, context).withName("GlacierJobParameters"));
      }
      if (input.OutputLocation !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlOutputLocation(input.OutputLocation, context).withName("OutputLocation"));
      }
      if (input.SelectParameters !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlSelectParameters(input.SelectParameters, context).withName("SelectParameters"));
      }
      if (input.Tier !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Tier")
              .addChildNode(new __XmlText(input.Tier))
              .withName("Tier"));
      }
      if (input.Type !== undefined) {
          bodyNode.addChildNode(new __XmlNode("RestoreRequestType")
              .addChildNode(new __XmlText(input.Type))
              .withName("Type"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlRoutingRule = function (input, context) {
      var bodyNode = new __XmlNode("RoutingRule");
      if (input.Condition !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlCondition(input.Condition, context).withName("Condition"));
      }
      if (input.Redirect !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlRedirect(input.Redirect, context).withName("Redirect"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlRoutingRules = function (input, context) {
      var e_17, _a;
      var collectedNodes = [];
      try {
          for (var input_17 = __values(input), input_17_1 = input_17.next(); !input_17_1.done; input_17_1 = input_17.next()) {
              var entry = input_17_1.value;
              var node = serializeAws_restXmlRoutingRule(entry, context);
              collectedNodes.push(node.withName("RoutingRule"));
          }
      }
      catch (e_17_1) { e_17 = { error: e_17_1 }; }
      finally {
          try {
              if (input_17_1 && !input_17_1.done && (_a = input_17.return)) _a.call(input_17);
          }
          finally { if (e_17) throw e_17.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlS3KeyFilter = function (input, context) {
      var bodyNode = new __XmlNode("S3KeyFilter");
      if (input.FilterRules !== undefined) {
          var nodes = serializeAws_restXmlFilterRuleList(input.FilterRules, context);
          nodes.map(function (node) {
              node = node.withName("FilterRule");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlS3Location = function (input, context) {
      var bodyNode = new __XmlNode("S3Location");
      if (input.AccessControlList !== undefined) {
          var nodes = serializeAws_restXmlGrants(input.AccessControlList, context);
          var containerNode_4 = new __XmlNode("AccessControlList");
          nodes.map(function (node) {
              containerNode_4.addChildNode(node);
          });
          bodyNode.addChildNode(containerNode_4);
      }
      if (input.BucketName !== undefined) {
          bodyNode.addChildNode(new __XmlNode("BucketName")
              .addChildNode(new __XmlText(input.BucketName))
              .withName("BucketName"));
      }
      if (input.CannedACL !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ObjectCannedACL")
              .addChildNode(new __XmlText(input.CannedACL))
              .withName("CannedACL"));
      }
      if (input.Encryption !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlEncryption(input.Encryption, context).withName("Encryption"));
      }
      if (input.Prefix !== undefined) {
          bodyNode.addChildNode(new __XmlNode("LocationPrefix")
              .addChildNode(new __XmlText(input.Prefix))
              .withName("Prefix"));
      }
      if (input.StorageClass !== undefined) {
          bodyNode.addChildNode(new __XmlNode("StorageClass")
              .addChildNode(new __XmlText(input.StorageClass))
              .withName("StorageClass"));
      }
      if (input.Tagging !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlTagging(input.Tagging, context).withName("Tagging"));
      }
      if (input.UserMetadata !== undefined) {
          var nodes = serializeAws_restXmlUserMetadata(input.UserMetadata, context);
          var containerNode_5 = new __XmlNode("UserMetadata");
          nodes.map(function (node) {
              containerNode_5.addChildNode(node);
          });
          bodyNode.addChildNode(containerNode_5);
      }
      return bodyNode;
  };
  var serializeAws_restXmlSSEKMS = function (input, context) {
      var bodyNode = new __XmlNode("SSE-KMS");
      if (input.KeyId !== undefined) {
          bodyNode.addChildNode(new __XmlNode("SSEKMSKeyId")
              .addChildNode(new __XmlText(input.KeyId))
              .withName("KeyId"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlSSES3 = function (input, context) {
      var bodyNode = new __XmlNode("SSE-S3");
      return bodyNode;
  };
  var serializeAws_restXmlScanRange = function (input, context) {
      var bodyNode = new __XmlNode("ScanRange");
      if (input.End !== undefined) {
          bodyNode.addChildNode(new __XmlNode("End")
              .addChildNode(new __XmlText(String(input.End)))
              .withName("End"));
      }
      if (input.Start !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Start")
              .addChildNode(new __XmlText(String(input.Start)))
              .withName("Start"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlSelectParameters = function (input, context) {
      var bodyNode = new __XmlNode("SelectParameters");
      if (input.Expression !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Expression")
              .addChildNode(new __XmlText(input.Expression))
              .withName("Expression"));
      }
      if (input.ExpressionType !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ExpressionType")
              .addChildNode(new __XmlText(input.ExpressionType))
              .withName("ExpressionType"));
      }
      if (input.InputSerialization !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlInputSerialization(input.InputSerialization, context).withName("InputSerialization"));
      }
      if (input.OutputSerialization !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlOutputSerialization(input.OutputSerialization, context).withName("OutputSerialization"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlServerSideEncryptionByDefault = function (input, context) {
      var bodyNode = new __XmlNode("ServerSideEncryptionByDefault");
      if (input.KMSMasterKeyID !== undefined) {
          bodyNode.addChildNode(new __XmlNode("SSEKMSKeyId")
              .addChildNode(new __XmlText(input.KMSMasterKeyID))
              .withName("KMSMasterKeyID"));
      }
      if (input.SSEAlgorithm !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ServerSideEncryption")
              .addChildNode(new __XmlText(input.SSEAlgorithm))
              .withName("SSEAlgorithm"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlServerSideEncryptionConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("ServerSideEncryptionConfiguration");
      if (input.Rules !== undefined) {
          var nodes = serializeAws_restXmlServerSideEncryptionRules(input.Rules, context);
          nodes.map(function (node) {
              node = node.withName("Rule");
              bodyNode.addChildNode(node);
          });
      }
      return bodyNode;
  };
  var serializeAws_restXmlServerSideEncryptionRule = function (input, context) {
      var bodyNode = new __XmlNode("ServerSideEncryptionRule");
      if (input.ApplyServerSideEncryptionByDefault !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlServerSideEncryptionByDefault(input.ApplyServerSideEncryptionByDefault, context).withName("ApplyServerSideEncryptionByDefault"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlServerSideEncryptionRules = function (input, context) {
      var e_18, _a;
      var collectedNodes = [];
      try {
          for (var input_18 = __values(input), input_18_1 = input_18.next(); !input_18_1.done; input_18_1 = input_18.next()) {
              var entry = input_18_1.value;
              var node = serializeAws_restXmlServerSideEncryptionRule(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_18_1) { e_18 = { error: e_18_1 }; }
      finally {
          try {
              if (input_18_1 && !input_18_1.done && (_a = input_18.return)) _a.call(input_18);
          }
          finally { if (e_18) throw e_18.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlSourceSelectionCriteria = function (input, context) {
      var bodyNode = new __XmlNode("SourceSelectionCriteria");
      if (input.SseKmsEncryptedObjects !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlSseKmsEncryptedObjects(input.SseKmsEncryptedObjects, context).withName("SseKmsEncryptedObjects"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlSseKmsEncryptedObjects = function (input, context) {
      var bodyNode = new __XmlNode("SseKmsEncryptedObjects");
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("SseKmsEncryptedObjectsStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlStorageClassAnalysis = function (input, context) {
      var bodyNode = new __XmlNode("StorageClassAnalysis");
      if (input.DataExport !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlStorageClassAnalysisDataExport(input.DataExport, context).withName("DataExport"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlStorageClassAnalysisDataExport = function (input, context) {
      var bodyNode = new __XmlNode("StorageClassAnalysisDataExport");
      if (input.Destination !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlAnalyticsExportDestination(input.Destination, context).withName("Destination"));
      }
      if (input.OutputSchemaVersion !== undefined) {
          bodyNode.addChildNode(new __XmlNode("StorageClassAnalysisSchemaVersion")
              .addChildNode(new __XmlText(input.OutputSchemaVersion))
              .withName("OutputSchemaVersion"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlTag = function (input, context) {
      var bodyNode = new __XmlNode("Tag");
      if (input.Key !== undefined) {
          bodyNode.addChildNode(new __XmlNode("ObjectKey")
              .addChildNode(new __XmlText(input.Key))
              .withName("Key"));
      }
      if (input.Value !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Value")
              .addChildNode(new __XmlText(input.Value))
              .withName("Value"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlTagSet = function (input, context) {
      var e_19, _a;
      var collectedNodes = [];
      try {
          for (var input_19 = __values(input), input_19_1 = input_19.next(); !input_19_1.done; input_19_1 = input_19.next()) {
              var entry = input_19_1.value;
              var node = serializeAws_restXmlTag(entry, context);
              collectedNodes.push(node.withName("Tag"));
          }
      }
      catch (e_19_1) { e_19 = { error: e_19_1 }; }
      finally {
          try {
              if (input_19_1 && !input_19_1.done && (_a = input_19.return)) _a.call(input_19);
          }
          finally { if (e_19) throw e_19.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlTagging = function (input, context) {
      var bodyNode = new __XmlNode("Tagging");
      if (input.TagSet !== undefined) {
          var nodes = serializeAws_restXmlTagSet(input.TagSet, context);
          var containerNode_6 = new __XmlNode("TagSet");
          nodes.map(function (node) {
              containerNode_6.addChildNode(node);
          });
          bodyNode.addChildNode(containerNode_6);
      }
      return bodyNode;
  };
  var serializeAws_restXmlTargetGrant = function (input, context) {
      var bodyNode = new __XmlNode("TargetGrant");
      if (input.Grantee !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlGrantee(input.Grantee, context).withName("Grantee"));
      }
      if (input.Permission !== undefined) {
          bodyNode.addChildNode(new __XmlNode("BucketLogsPermission")
              .addChildNode(new __XmlText(input.Permission))
              .withName("Permission"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlTargetGrants = function (input, context) {
      var e_20, _a;
      var collectedNodes = [];
      try {
          for (var input_20 = __values(input), input_20_1 = input_20.next(); !input_20_1.done; input_20_1 = input_20.next()) {
              var entry = input_20_1.value;
              var node = serializeAws_restXmlTargetGrant(entry, context);
              collectedNodes.push(node.withName("Grant"));
          }
      }
      catch (e_20_1) { e_20 = { error: e_20_1 }; }
      finally {
          try {
              if (input_20_1 && !input_20_1.done && (_a = input_20.return)) _a.call(input_20);
          }
          finally { if (e_20) throw e_20.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlTopicConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("TopicConfiguration");
      if (input.Events !== undefined) {
          var nodes = serializeAws_restXmlEventList(input.Events, context);
          nodes.map(function (node) {
              node = node.withName("Event");
              bodyNode.addChildNode(node);
          });
      }
      if (input.Filter !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlNotificationConfigurationFilter(input.Filter, context).withName("Filter"));
      }
      if (input.Id !== undefined) {
          bodyNode.addChildNode(new __XmlNode("NotificationId")
              .addChildNode(new __XmlText(input.Id))
              .withName("Id"));
      }
      if (input.TopicArn !== undefined) {
          bodyNode.addChildNode(new __XmlNode("TopicArn")
              .addChildNode(new __XmlText(input.TopicArn))
              .withName("Topic"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlTopicConfigurationList = function (input, context) {
      var e_21, _a;
      var collectedNodes = [];
      try {
          for (var input_21 = __values(input), input_21_1 = input_21.next(); !input_21_1.done; input_21_1 = input_21.next()) {
              var entry = input_21_1.value;
              var node = serializeAws_restXmlTopicConfiguration(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_21_1) { e_21 = { error: e_21_1 }; }
      finally {
          try {
              if (input_21_1 && !input_21_1.done && (_a = input_21.return)) _a.call(input_21);
          }
          finally { if (e_21) throw e_21.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlTransition = function (input, context) {
      var bodyNode = new __XmlNode("Transition");
      if (input.Date !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Date")
              .addChildNode(new __XmlText(input.Date.toISOString().split(".")[0] + "Z"))
              .withName("Date"));
      }
      if (input.Days !== undefined) {
          bodyNode.addChildNode(new __XmlNode("Days")
              .addChildNode(new __XmlText(String(input.Days)))
              .withName("Days"));
      }
      if (input.StorageClass !== undefined) {
          bodyNode.addChildNode(new __XmlNode("TransitionStorageClass")
              .addChildNode(new __XmlText(input.StorageClass))
              .withName("StorageClass"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlTransitionList = function (input, context) {
      var e_22, _a;
      var collectedNodes = [];
      try {
          for (var input_22 = __values(input), input_22_1 = input_22.next(); !input_22_1.done; input_22_1 = input_22.next()) {
              var entry = input_22_1.value;
              var node = serializeAws_restXmlTransition(entry, context);
              collectedNodes.push(node.withName("member"));
          }
      }
      catch (e_22_1) { e_22 = { error: e_22_1 }; }
      finally {
          try {
              if (input_22_1 && !input_22_1.done && (_a = input_22.return)) _a.call(input_22);
          }
          finally { if (e_22) throw e_22.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlUserMetadata = function (input, context) {
      var e_23, _a;
      var collectedNodes = [];
      try {
          for (var input_23 = __values(input), input_23_1 = input_23.next(); !input_23_1.done; input_23_1 = input_23.next()) {
              var entry = input_23_1.value;
              var node = serializeAws_restXmlMetadataEntry(entry, context);
              collectedNodes.push(node.withName("MetadataEntry"));
          }
      }
      catch (e_23_1) { e_23 = { error: e_23_1 }; }
      finally {
          try {
              if (input_23_1 && !input_23_1.done && (_a = input_23.return)) _a.call(input_23);
          }
          finally { if (e_23) throw e_23.error; }
      }
      return collectedNodes;
  };
  var serializeAws_restXmlVersioningConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("VersioningConfiguration");
      if (input.MFADelete !== undefined) {
          bodyNode.addChildNode(new __XmlNode("MFADelete")
              .addChildNode(new __XmlText(input.MFADelete))
              .withName("MfaDelete"));
      }
      if (input.Status !== undefined) {
          bodyNode.addChildNode(new __XmlNode("BucketVersioningStatus")
              .addChildNode(new __XmlText(input.Status))
              .withName("Status"));
      }
      return bodyNode;
  };
  var serializeAws_restXmlWebsiteConfiguration = function (input, context) {
      var bodyNode = new __XmlNode("WebsiteConfiguration");
      if (input.ErrorDocument !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlErrorDocument(input.ErrorDocument, context).withName("ErrorDocument"));
      }
      if (input.IndexDocument !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlIndexDocument(input.IndexDocument, context).withName("IndexDocument"));
      }
      if (input.RedirectAllRequestsTo !== undefined) {
          bodyNode.addChildNode(serializeAws_restXmlRedirectAllRequestsTo(input.RedirectAllRequestsTo, context).withName("RedirectAllRequestsTo"));
      }
      if (input.RoutingRules !== undefined) {
          var nodes = serializeAws_restXmlRoutingRules(input.RoutingRules, context);
          var containerNode_7 = new __XmlNode("RoutingRules");
          nodes.map(function (node) {
              containerNode_7.addChildNode(node);
          });
          bodyNode.addChildNode(containerNode_7);
      }
      return bodyNode;
  };
  var deserializeAws_restXmlAbortIncompleteMultipartUpload = function (output, context) {
      var contents = {
          __type: "AbortIncompleteMultipartUpload",
          DaysAfterInitiation: undefined
      };
      if (output["DaysAfterInitiation"] !== undefined) {
          contents.DaysAfterInitiation = parseInt(output["DaysAfterInitiation"]);
      }
      return contents;
  };
  var deserializeAws_restXmlAccessControlTranslation = function (output, context) {
      var contents = {
          __type: "AccessControlTranslation",
          Owner: undefined
      };
      if (output["Owner"] !== undefined) {
          contents.Owner = output["Owner"];
      }
      return contents;
  };
  var deserializeAws_restXmlAllowedHeaders = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(entry);
      });
      return contents;
  };
  var deserializeAws_restXmlAllowedMethods = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(entry);
      });
      return contents;
  };
  var deserializeAws_restXmlAllowedOrigins = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(entry);
      });
      return contents;
  };
  var deserializeAws_restXmlAnalyticsAndOperator = function (output, context) {
      var contents = {
          __type: "AnalyticsAndOperator",
          Prefix: undefined,
          Tags: undefined
      };
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output.Tag === "") {
          contents.Tags = [];
      }
      if (output["Tag"] !== undefined) {
          var wrappedItem = output["Tag"] instanceof Array ? output["Tag"] : [output["Tag"]];
          contents.Tags = deserializeAws_restXmlTagSet(wrappedItem, context);
      }
      return contents;
  };
  var deserializeAws_restXmlAnalyticsConfiguration = function (output, context) {
      var contents = {
          __type: "AnalyticsConfiguration",
          Filter: undefined,
          Id: undefined,
          StorageClassAnalysis: undefined
      };
      if (output["Filter"] !== undefined) {
          contents.Filter = deserializeAws_restXmlAnalyticsFilter(output["Filter"], context);
      }
      if (output["Id"] !== undefined) {
          contents.Id = output["Id"];
      }
      if (output["StorageClassAnalysis"] !== undefined) {
          contents.StorageClassAnalysis = deserializeAws_restXmlStorageClassAnalysis(output["StorageClassAnalysis"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlAnalyticsConfigurationList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlAnalyticsConfiguration(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlAnalyticsExportDestination = function (output, context) {
      var contents = {
          __type: "AnalyticsExportDestination",
          S3BucketDestination: undefined
      };
      if (output["S3BucketDestination"] !== undefined) {
          contents.S3BucketDestination = deserializeAws_restXmlAnalyticsS3BucketDestination(output["S3BucketDestination"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlAnalyticsFilter = function (output, context) {
      var contents = {
          __type: "AnalyticsFilter",
          And: undefined,
          Prefix: undefined,
          Tag: undefined
      };
      if (output["And"] !== undefined) {
          contents.And = deserializeAws_restXmlAnalyticsAndOperator(output["And"], context);
      }
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output["Tag"] !== undefined) {
          contents.Tag = deserializeAws_restXmlTag(output["Tag"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlAnalyticsS3BucketDestination = function (output, context) {
      var contents = {
          __type: "AnalyticsS3BucketDestination",
          Bucket: undefined,
          BucketAccountId: undefined,
          Format: undefined,
          Prefix: undefined
      };
      if (output["Bucket"] !== undefined) {
          contents.Bucket = output["Bucket"];
      }
      if (output["BucketAccountId"] !== undefined) {
          contents.BucketAccountId = output["BucketAccountId"];
      }
      if (output["Format"] !== undefined) {
          contents.Format = output["Format"];
      }
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      return contents;
  };
  var deserializeAws_restXmlBucket = function (output, context) {
      var contents = {
          __type: "Bucket",
          CreationDate: undefined,
          Name: undefined
      };
      if (output["CreationDate"] !== undefined) {
          contents.CreationDate = new Date(output["CreationDate"]);
      }
      if (output["Name"] !== undefined) {
          contents.Name = output["Name"];
      }
      return contents;
  };
  var deserializeAws_restXmlBuckets = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlBucket(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlCORSRule = function (output, context) {
      var contents = {
          __type: "CORSRule",
          AllowedHeaders: undefined,
          AllowedMethods: undefined,
          AllowedOrigins: undefined,
          ExposeHeaders: undefined,
          MaxAgeSeconds: undefined
      };
      if (output.AllowedHeader === "") {
          contents.AllowedHeaders = [];
      }
      if (output["AllowedHeader"] !== undefined) {
          var wrappedItem = output["AllowedHeader"] instanceof Array
              ? output["AllowedHeader"]
              : [output["AllowedHeader"]];
          contents.AllowedHeaders = deserializeAws_restXmlAllowedHeaders(wrappedItem, context);
      }
      if (output.AllowedMethod === "") {
          contents.AllowedMethods = [];
      }
      if (output["AllowedMethod"] !== undefined) {
          var wrappedItem = output["AllowedMethod"] instanceof Array
              ? output["AllowedMethod"]
              : [output["AllowedMethod"]];
          contents.AllowedMethods = deserializeAws_restXmlAllowedMethods(wrappedItem, context);
      }
      if (output.AllowedOrigin === "") {
          contents.AllowedOrigins = [];
      }
      if (output["AllowedOrigin"] !== undefined) {
          var wrappedItem = output["AllowedOrigin"] instanceof Array
              ? output["AllowedOrigin"]
              : [output["AllowedOrigin"]];
          contents.AllowedOrigins = deserializeAws_restXmlAllowedOrigins(wrappedItem, context);
      }
      if (output.ExposeHeader === "") {
          contents.ExposeHeaders = [];
      }
      if (output["ExposeHeader"] !== undefined) {
          var wrappedItem = output["ExposeHeader"] instanceof Array
              ? output["ExposeHeader"]
              : [output["ExposeHeader"]];
          contents.ExposeHeaders = deserializeAws_restXmlExposeHeaders(wrappedItem, context);
      }
      if (output["MaxAgeSeconds"] !== undefined) {
          contents.MaxAgeSeconds = parseInt(output["MaxAgeSeconds"]);
      }
      return contents;
  };
  var deserializeAws_restXmlCORSRules = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlCORSRule(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlCommonPrefix = function (output, context) {
      var contents = {
          __type: "CommonPrefix",
          Prefix: undefined
      };
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      return contents;
  };
  var deserializeAws_restXmlCommonPrefixList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlCommonPrefix(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlCondition = function (output, context) {
      var contents = {
          __type: "Condition",
          HttpErrorCodeReturnedEquals: undefined,
          KeyPrefixEquals: undefined
      };
      if (output["HttpErrorCodeReturnedEquals"] !== undefined) {
          contents.HttpErrorCodeReturnedEquals =
              output["HttpErrorCodeReturnedEquals"];
      }
      if (output["KeyPrefixEquals"] !== undefined) {
          contents.KeyPrefixEquals = output["KeyPrefixEquals"];
      }
      return contents;
  };
  var deserializeAws_restXmlCopyObjectResult = function (output, context) {
      var contents = {
          __type: "CopyObjectResult",
          ETag: undefined,
          LastModified: undefined
      };
      if (output["ETag"] !== undefined) {
          contents.ETag = output["ETag"];
      }
      if (output["LastModified"] !== undefined) {
          contents.LastModified = new Date(output["LastModified"]);
      }
      return contents;
  };
  var deserializeAws_restXmlCopyPartResult = function (output, context) {
      var contents = {
          __type: "CopyPartResult",
          ETag: undefined,
          LastModified: undefined
      };
      if (output["ETag"] !== undefined) {
          contents.ETag = output["ETag"];
      }
      if (output["LastModified"] !== undefined) {
          contents.LastModified = new Date(output["LastModified"]);
      }
      return contents;
  };
  var deserializeAws_restXmlDefaultRetention = function (output, context) {
      var contents = {
          __type: "DefaultRetention",
          Days: undefined,
          Mode: undefined,
          Years: undefined
      };
      if (output["Days"] !== undefined) {
          contents.Days = parseInt(output["Days"]);
      }
      if (output["Mode"] !== undefined) {
          contents.Mode = output["Mode"];
      }
      if (output["Years"] !== undefined) {
          contents.Years = parseInt(output["Years"]);
      }
      return contents;
  };
  var deserializeAws_restXmlDeleteMarkerEntry = function (output, context) {
      var contents = {
          __type: "DeleteMarkerEntry",
          IsLatest: undefined,
          Key: undefined,
          LastModified: undefined,
          Owner: undefined,
          VersionId: undefined
      };
      if (output["IsLatest"] !== undefined) {
          contents.IsLatest = output["IsLatest"] == "true";
      }
      if (output["Key"] !== undefined) {
          contents.Key = output["Key"];
      }
      if (output["LastModified"] !== undefined) {
          contents.LastModified = new Date(output["LastModified"]);
      }
      if (output["Owner"] !== undefined) {
          contents.Owner = deserializeAws_restXmlOwner(output["Owner"], context);
      }
      if (output["VersionId"] !== undefined) {
          contents.VersionId = output["VersionId"];
      }
      return contents;
  };
  var deserializeAws_restXmlDeleteMarkerReplication = function (output, context) {
      var contents = {
          __type: "DeleteMarkerReplication",
          Status: undefined
      };
      if (output["Status"] !== undefined) {
          contents.Status = output["Status"];
      }
      return contents;
  };
  var deserializeAws_restXmlDeleteMarkers = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlDeleteMarkerEntry(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlDeletedObject = function (output, context) {
      var contents = {
          __type: "DeletedObject",
          DeleteMarker: undefined,
          DeleteMarkerVersionId: undefined,
          Key: undefined,
          VersionId: undefined
      };
      if (output["DeleteMarker"] !== undefined) {
          contents.DeleteMarker = output["DeleteMarker"] == "true";
      }
      if (output["DeleteMarkerVersionId"] !== undefined) {
          contents.DeleteMarkerVersionId = output["DeleteMarkerVersionId"];
      }
      if (output["Key"] !== undefined) {
          contents.Key = output["Key"];
      }
      if (output["VersionId"] !== undefined) {
          contents.VersionId = output["VersionId"];
      }
      return contents;
  };
  var deserializeAws_restXmlDeletedObjects = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlDeletedObject(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlDestination = function (output, context) {
      var contents = {
          __type: "Destination",
          AccessControlTranslation: undefined,
          Account: undefined,
          Bucket: undefined,
          EncryptionConfiguration: undefined,
          Metrics: undefined,
          ReplicationTime: undefined,
          StorageClass: undefined
      };
      if (output["AccessControlTranslation"] !== undefined) {
          contents.AccessControlTranslation = deserializeAws_restXmlAccessControlTranslation(output["AccessControlTranslation"], context);
      }
      if (output["Account"] !== undefined) {
          contents.Account = output["Account"];
      }
      if (output["Bucket"] !== undefined) {
          contents.Bucket = output["Bucket"];
      }
      if (output["EncryptionConfiguration"] !== undefined) {
          contents.EncryptionConfiguration = deserializeAws_restXmlEncryptionConfiguration(output["EncryptionConfiguration"], context);
      }
      if (output["Metrics"] !== undefined) {
          contents.Metrics = deserializeAws_restXmlMetrics(output["Metrics"], context);
      }
      if (output["ReplicationTime"] !== undefined) {
          contents.ReplicationTime = deserializeAws_restXmlReplicationTime(output["ReplicationTime"], context);
      }
      if (output["StorageClass"] !== undefined) {
          contents.StorageClass = output["StorageClass"];
      }
      return contents;
  };
  var deserializeAws_restXmlEncryptionConfiguration = function (output, context) {
      var contents = {
          __type: "EncryptionConfiguration",
          ReplicaKmsKeyID: undefined
      };
      if (output["ReplicaKmsKeyID"] !== undefined) {
          contents.ReplicaKmsKeyID = output["ReplicaKmsKeyID"];
      }
      return contents;
  };
  var deserializeAws_restXml_Error = function (output, context) {
      var contents = {
          __type: "Error",
          Code: undefined,
          Key: undefined,
          Message: undefined,
          VersionId: undefined
      };
      if (output["Code"] !== undefined) {
          contents.Code = output["Code"];
      }
      if (output["Key"] !== undefined) {
          contents.Key = output["Key"];
      }
      if (output["Message"] !== undefined) {
          contents.Message = output["Message"];
      }
      if (output["VersionId"] !== undefined) {
          contents.VersionId = output["VersionId"];
      }
      return contents;
  };
  var deserializeAws_restXmlErrorDocument = function (output, context) {
      var contents = {
          __type: "ErrorDocument",
          Key: undefined
      };
      if (output["Key"] !== undefined) {
          contents.Key = output["Key"];
      }
      return contents;
  };
  var deserializeAws_restXmlErrors = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXml_Error(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlEventList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(entry);
      });
      return contents;
  };
  var deserializeAws_restXmlExistingObjectReplication = function (output, context) {
      var contents = {
          __type: "ExistingObjectReplication",
          Status: undefined
      };
      if (output["Status"] !== undefined) {
          contents.Status = output["Status"];
      }
      return contents;
  };
  var deserializeAws_restXmlExposeHeaders = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(entry);
      });
      return contents;
  };
  var deserializeAws_restXmlFilterRule = function (output, context) {
      var contents = {
          __type: "FilterRule",
          Name: undefined,
          Value: undefined
      };
      if (output["Name"] !== undefined) {
          contents.Name = output["Name"];
      }
      if (output["Value"] !== undefined) {
          contents.Value = output["Value"];
      }
      return contents;
  };
  var deserializeAws_restXmlFilterRuleList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlFilterRule(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlGrant = function (output, context) {
      var contents = {
          __type: "Grant",
          Grantee: undefined,
          Permission: undefined
      };
      if (output["Grantee"] !== undefined) {
          contents.Grantee = deserializeAws_restXmlGrantee(output["Grantee"], context);
      }
      if (output["Permission"] !== undefined) {
          contents.Permission = output["Permission"];
      }
      return contents;
  };
  var deserializeAws_restXmlGrantee = function (output, context) {
      var contents = {
          __type: "Grantee",
          DisplayName: undefined,
          EmailAddress: undefined,
          ID: undefined,
          Type: undefined,
          URI: undefined
      };
      if (output["DisplayName"] !== undefined) {
          contents.DisplayName = output["DisplayName"];
      }
      if (output["EmailAddress"] !== undefined) {
          contents.EmailAddress = output["EmailAddress"];
      }
      if (output["ID"] !== undefined) {
          contents.ID = output["ID"];
      }
      if (output["xsi:type"] !== undefined) {
          contents.Type = output["xsi:type"];
      }
      if (output["URI"] !== undefined) {
          contents.URI = output["URI"];
      }
      return contents;
  };
  var deserializeAws_restXmlGrants = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlGrant(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlIndexDocument = function (output, context) {
      var contents = {
          __type: "IndexDocument",
          Suffix: undefined
      };
      if (output["Suffix"] !== undefined) {
          contents.Suffix = output["Suffix"];
      }
      return contents;
  };
  var deserializeAws_restXmlInitiator = function (output, context) {
      var contents = {
          __type: "Initiator",
          DisplayName: undefined,
          ID: undefined
      };
      if (output["DisplayName"] !== undefined) {
          contents.DisplayName = output["DisplayName"];
      }
      if (output["ID"] !== undefined) {
          contents.ID = output["ID"];
      }
      return contents;
  };
  var deserializeAws_restXmlInventoryConfiguration = function (output, context) {
      var contents = {
          __type: "InventoryConfiguration",
          Destination: undefined,
          Filter: undefined,
          Id: undefined,
          IncludedObjectVersions: undefined,
          IsEnabled: undefined,
          OptionalFields: undefined,
          Schedule: undefined
      };
      if (output["Destination"] !== undefined) {
          contents.Destination = deserializeAws_restXmlInventoryDestination(output["Destination"], context);
      }
      if (output["Filter"] !== undefined) {
          contents.Filter = deserializeAws_restXmlInventoryFilter(output["Filter"], context);
      }
      if (output["Id"] !== undefined) {
          contents.Id = output["Id"];
      }
      if (output["IncludedObjectVersions"] !== undefined) {
          contents.IncludedObjectVersions = output["IncludedObjectVersions"];
      }
      if (output["IsEnabled"] !== undefined) {
          contents.IsEnabled = output["IsEnabled"] == "true";
      }
      if (output.OptionalFields === "") {
          contents.OptionalFields = [];
      }
      if (output["OptionalFields"] !== undefined &&
          output["OptionalFields"]["Field"] !== undefined) {
          var wrappedItem = output["OptionalFields"]["Field"] instanceof Array
              ? output["OptionalFields"]["Field"]
              : [output["OptionalFields"]["Field"]];
          contents.OptionalFields = deserializeAws_restXmlInventoryOptionalFields(wrappedItem, context);
      }
      if (output["Schedule"] !== undefined) {
          contents.Schedule = deserializeAws_restXmlInventorySchedule(output["Schedule"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlInventoryConfigurationList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlInventoryConfiguration(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlInventoryDestination = function (output, context) {
      var contents = {
          __type: "InventoryDestination",
          S3BucketDestination: undefined
      };
      if (output["S3BucketDestination"] !== undefined) {
          contents.S3BucketDestination = deserializeAws_restXmlInventoryS3BucketDestination(output["S3BucketDestination"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlInventoryEncryption = function (output, context) {
      var contents = {
          __type: "InventoryEncryption",
          SSEKMS: undefined,
          SSES3: undefined
      };
      if (output["SSE-KMS"] !== undefined) {
          contents.SSEKMS = deserializeAws_restXmlSSEKMS(output["SSE-KMS"], context);
      }
      if (output["SSE-S3"] !== undefined) {
          contents.SSES3 = deserializeAws_restXmlSSES3(output["SSE-S3"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlInventoryFilter = function (output, context) {
      var contents = {
          __type: "InventoryFilter",
          Prefix: undefined
      };
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      return contents;
  };
  var deserializeAws_restXmlInventoryOptionalFields = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(entry);
      });
      return contents;
  };
  var deserializeAws_restXmlInventoryS3BucketDestination = function (output, context) {
      var contents = {
          __type: "InventoryS3BucketDestination",
          AccountId: undefined,
          Bucket: undefined,
          Encryption: undefined,
          Format: undefined,
          Prefix: undefined
      };
      if (output["AccountId"] !== undefined) {
          contents.AccountId = output["AccountId"];
      }
      if (output["Bucket"] !== undefined) {
          contents.Bucket = output["Bucket"];
      }
      if (output["Encryption"] !== undefined) {
          contents.Encryption = deserializeAws_restXmlInventoryEncryption(output["Encryption"], context);
      }
      if (output["Format"] !== undefined) {
          contents.Format = output["Format"];
      }
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      return contents;
  };
  var deserializeAws_restXmlInventorySchedule = function (output, context) {
      var contents = {
          __type: "InventorySchedule",
          Frequency: undefined
      };
      if (output["Frequency"] !== undefined) {
          contents.Frequency = output["Frequency"];
      }
      return contents;
  };
  var deserializeAws_restXmlLambdaFunctionConfiguration = function (output, context) {
      var contents = {
          __type: "LambdaFunctionConfiguration",
          Events: undefined,
          Filter: undefined,
          Id: undefined,
          LambdaFunctionArn: undefined
      };
      if (output.Event === "") {
          contents.Events = [];
      }
      if (output["Event"] !== undefined) {
          var wrappedItem = output["Event"] instanceof Array ? output["Event"] : [output["Event"]];
          contents.Events = deserializeAws_restXmlEventList(wrappedItem, context);
      }
      if (output["Filter"] !== undefined) {
          contents.Filter = deserializeAws_restXmlNotificationConfigurationFilter(output["Filter"], context);
      }
      if (output["Id"] !== undefined) {
          contents.Id = output["Id"];
      }
      if (output["CloudFunction"] !== undefined) {
          contents.LambdaFunctionArn = output["CloudFunction"];
      }
      return contents;
  };
  var deserializeAws_restXmlLambdaFunctionConfigurationList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlLambdaFunctionConfiguration(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlLifecycleExpiration = function (output, context) {
      var contents = {
          __type: "LifecycleExpiration",
          Date: undefined,
          Days: undefined,
          ExpiredObjectDeleteMarker: undefined
      };
      if (output["Date"] !== undefined) {
          contents.Date = new Date(output["Date"]);
      }
      if (output["Days"] !== undefined) {
          contents.Days = parseInt(output["Days"]);
      }
      if (output["ExpiredObjectDeleteMarker"] !== undefined) {
          contents.ExpiredObjectDeleteMarker =
              output["ExpiredObjectDeleteMarker"] == "true";
      }
      return contents;
  };
  var deserializeAws_restXmlLifecycleRule = function (output, context) {
      var contents = {
          __type: "LifecycleRule",
          AbortIncompleteMultipartUpload: undefined,
          Expiration: undefined,
          Filter: undefined,
          ID: undefined,
          NoncurrentVersionExpiration: undefined,
          NoncurrentVersionTransitions: undefined,
          Prefix: undefined,
          Status: undefined,
          Transitions: undefined
      };
      if (output["AbortIncompleteMultipartUpload"] !== undefined) {
          contents.AbortIncompleteMultipartUpload = deserializeAws_restXmlAbortIncompleteMultipartUpload(output["AbortIncompleteMultipartUpload"], context);
      }
      if (output["Expiration"] !== undefined) {
          contents.Expiration = deserializeAws_restXmlLifecycleExpiration(output["Expiration"], context);
      }
      if (output["Filter"] !== undefined) {
          contents.Filter = deserializeAws_restXmlLifecycleRuleFilter(output["Filter"], context);
      }
      if (output["ID"] !== undefined) {
          contents.ID = output["ID"];
      }
      if (output["NoncurrentVersionExpiration"] !== undefined) {
          contents.NoncurrentVersionExpiration = deserializeAws_restXmlNoncurrentVersionExpiration(output["NoncurrentVersionExpiration"], context);
      }
      if (output.NoncurrentVersionTransition === "") {
          contents.NoncurrentVersionTransitions = [];
      }
      if (output["NoncurrentVersionTransition"] !== undefined) {
          var wrappedItem = output["NoncurrentVersionTransition"] instanceof Array
              ? output["NoncurrentVersionTransition"]
              : [output["NoncurrentVersionTransition"]];
          contents.NoncurrentVersionTransitions = deserializeAws_restXmlNoncurrentVersionTransitionList(wrappedItem, context);
      }
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output["Status"] !== undefined) {
          contents.Status = output["Status"];
      }
      if (output.Transition === "") {
          contents.Transitions = [];
      }
      if (output["Transition"] !== undefined) {
          var wrappedItem = output["Transition"] instanceof Array
              ? output["Transition"]
              : [output["Transition"]];
          contents.Transitions = deserializeAws_restXmlTransitionList(wrappedItem, context);
      }
      return contents;
  };
  var deserializeAws_restXmlLifecycleRuleAndOperator = function (output, context) {
      var contents = {
          __type: "LifecycleRuleAndOperator",
          Prefix: undefined,
          Tags: undefined
      };
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output.Tag === "") {
          contents.Tags = [];
      }
      if (output["Tag"] !== undefined) {
          var wrappedItem = output["Tag"] instanceof Array ? output["Tag"] : [output["Tag"]];
          contents.Tags = deserializeAws_restXmlTagSet(wrappedItem, context);
      }
      return contents;
  };
  var deserializeAws_restXmlLifecycleRuleFilter = function (output, context) {
      var contents = {
          __type: "LifecycleRuleFilter",
          And: undefined,
          Prefix: undefined,
          Tag: undefined
      };
      if (output["And"] !== undefined) {
          contents.And = deserializeAws_restXmlLifecycleRuleAndOperator(output["And"], context);
      }
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output["Tag"] !== undefined) {
          contents.Tag = deserializeAws_restXmlTag(output["Tag"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlLifecycleRules = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlLifecycleRule(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlLoggingEnabled = function (output, context) {
      var contents = {
          __type: "LoggingEnabled",
          TargetBucket: undefined,
          TargetGrants: undefined,
          TargetPrefix: undefined
      };
      if (output["TargetBucket"] !== undefined) {
          contents.TargetBucket = output["TargetBucket"];
      }
      if (output.TargetGrants === "") {
          contents.TargetGrants = [];
      }
      if (output["TargetGrants"] !== undefined &&
          output["TargetGrants"]["Grant"] !== undefined) {
          var wrappedItem = output["TargetGrants"]["Grant"] instanceof Array
              ? output["TargetGrants"]["Grant"]
              : [output["TargetGrants"]["Grant"]];
          contents.TargetGrants = deserializeAws_restXmlTargetGrants(wrappedItem, context);
      }
      if (output["TargetPrefix"] !== undefined) {
          contents.TargetPrefix = output["TargetPrefix"];
      }
      return contents;
  };
  var deserializeAws_restXmlMetrics = function (output, context) {
      var contents = {
          __type: "Metrics",
          EventThreshold: undefined,
          Status: undefined
      };
      if (output["EventThreshold"] !== undefined) {
          contents.EventThreshold = deserializeAws_restXmlReplicationTimeValue(output["EventThreshold"], context);
      }
      if (output["Status"] !== undefined) {
          contents.Status = output["Status"];
      }
      return contents;
  };
  var deserializeAws_restXmlMetricsAndOperator = function (output, context) {
      var contents = {
          __type: "MetricsAndOperator",
          Prefix: undefined,
          Tags: undefined
      };
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output.Tag === "") {
          contents.Tags = [];
      }
      if (output["Tag"] !== undefined) {
          var wrappedItem = output["Tag"] instanceof Array ? output["Tag"] : [output["Tag"]];
          contents.Tags = deserializeAws_restXmlTagSet(wrappedItem, context);
      }
      return contents;
  };
  var deserializeAws_restXmlMetricsConfiguration = function (output, context) {
      var contents = {
          __type: "MetricsConfiguration",
          Filter: undefined,
          Id: undefined
      };
      if (output["Filter"] !== undefined) {
          contents.Filter = deserializeAws_restXmlMetricsFilter(output["Filter"], context);
      }
      if (output["Id"] !== undefined) {
          contents.Id = output["Id"];
      }
      return contents;
  };
  var deserializeAws_restXmlMetricsConfigurationList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlMetricsConfiguration(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlMetricsFilter = function (output, context) {
      var contents = {
          __type: "MetricsFilter",
          And: undefined,
          Prefix: undefined,
          Tag: undefined
      };
      if (output["And"] !== undefined) {
          contents.And = deserializeAws_restXmlMetricsAndOperator(output["And"], context);
      }
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output["Tag"] !== undefined) {
          contents.Tag = deserializeAws_restXmlTag(output["Tag"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlMultipartUpload = function (output, context) {
      var contents = {
          __type: "MultipartUpload",
          Initiated: undefined,
          Initiator: undefined,
          Key: undefined,
          Owner: undefined,
          StorageClass: undefined,
          UploadId: undefined
      };
      if (output["Initiated"] !== undefined) {
          contents.Initiated = new Date(output["Initiated"]);
      }
      if (output["Initiator"] !== undefined) {
          contents.Initiator = deserializeAws_restXmlInitiator(output["Initiator"], context);
      }
      if (output["Key"] !== undefined) {
          contents.Key = output["Key"];
      }
      if (output["Owner"] !== undefined) {
          contents.Owner = deserializeAws_restXmlOwner(output["Owner"], context);
      }
      if (output["StorageClass"] !== undefined) {
          contents.StorageClass = output["StorageClass"];
      }
      if (output["UploadId"] !== undefined) {
          contents.UploadId = output["UploadId"];
      }
      return contents;
  };
  var deserializeAws_restXmlMultipartUploadList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlMultipartUpload(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlNoncurrentVersionExpiration = function (output, context) {
      var contents = {
          __type: "NoncurrentVersionExpiration",
          NoncurrentDays: undefined
      };
      if (output["NoncurrentDays"] !== undefined) {
          contents.NoncurrentDays = parseInt(output["NoncurrentDays"]);
      }
      return contents;
  };
  var deserializeAws_restXmlNoncurrentVersionTransition = function (output, context) {
      var contents = {
          __type: "NoncurrentVersionTransition",
          NoncurrentDays: undefined,
          StorageClass: undefined
      };
      if (output["NoncurrentDays"] !== undefined) {
          contents.NoncurrentDays = parseInt(output["NoncurrentDays"]);
      }
      if (output["StorageClass"] !== undefined) {
          contents.StorageClass = output["StorageClass"];
      }
      return contents;
  };
  var deserializeAws_restXmlNoncurrentVersionTransitionList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlNoncurrentVersionTransition(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlNotificationConfigurationFilter = function (output, context) {
      var contents = {
          __type: "NotificationConfigurationFilter",
          Key: undefined
      };
      if (output["S3Key"] !== undefined) {
          contents.Key = deserializeAws_restXmlS3KeyFilter(output["S3Key"], context);
      }
      return contents;
  };
  var deserializeAws_restXml_Object = function (output, context) {
      var contents = {
          __type: "Object",
          ETag: undefined,
          Key: undefined,
          LastModified: undefined,
          Owner: undefined,
          Size: undefined,
          StorageClass: undefined
      };
      if (output["ETag"] !== undefined) {
          contents.ETag = output["ETag"];
      }
      if (output["Key"] !== undefined) {
          contents.Key = output["Key"];
      }
      if (output["LastModified"] !== undefined) {
          contents.LastModified = new Date(output["LastModified"]);
      }
      if (output["Owner"] !== undefined) {
          contents.Owner = deserializeAws_restXmlOwner(output["Owner"], context);
      }
      if (output["Size"] !== undefined) {
          contents.Size = parseInt(output["Size"]);
      }
      if (output["StorageClass"] !== undefined) {
          contents.StorageClass = output["StorageClass"];
      }
      return contents;
  };
  var deserializeAws_restXmlObjectList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXml_Object(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlObjectLockConfiguration = function (output, context) {
      var contents = {
          __type: "ObjectLockConfiguration",
          ObjectLockEnabled: undefined,
          Rule: undefined
      };
      if (output["ObjectLockEnabled"] !== undefined) {
          contents.ObjectLockEnabled = output["ObjectLockEnabled"];
      }
      if (output["Rule"] !== undefined) {
          contents.Rule = deserializeAws_restXmlObjectLockRule(output["Rule"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlObjectLockLegalHold = function (output, context) {
      var contents = {
          __type: "ObjectLockLegalHold",
          Status: undefined
      };
      if (output["Status"] !== undefined) {
          contents.Status = output["Status"];
      }
      return contents;
  };
  var deserializeAws_restXmlObjectLockRetention = function (output, context) {
      var contents = {
          __type: "ObjectLockRetention",
          Mode: undefined,
          RetainUntilDate: undefined
      };
      if (output["Mode"] !== undefined) {
          contents.Mode = output["Mode"];
      }
      if (output["RetainUntilDate"] !== undefined) {
          contents.RetainUntilDate = new Date(output["RetainUntilDate"]);
      }
      return contents;
  };
  var deserializeAws_restXmlObjectLockRule = function (output, context) {
      var contents = {
          __type: "ObjectLockRule",
          DefaultRetention: undefined
      };
      if (output["DefaultRetention"] !== undefined) {
          contents.DefaultRetention = deserializeAws_restXmlDefaultRetention(output["DefaultRetention"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlObjectVersion = function (output, context) {
      var contents = {
          __type: "ObjectVersion",
          ETag: undefined,
          IsLatest: undefined,
          Key: undefined,
          LastModified: undefined,
          Owner: undefined,
          Size: undefined,
          StorageClass: undefined,
          VersionId: undefined
      };
      if (output["ETag"] !== undefined) {
          contents.ETag = output["ETag"];
      }
      if (output["IsLatest"] !== undefined) {
          contents.IsLatest = output["IsLatest"] == "true";
      }
      if (output["Key"] !== undefined) {
          contents.Key = output["Key"];
      }
      if (output["LastModified"] !== undefined) {
          contents.LastModified = new Date(output["LastModified"]);
      }
      if (output["Owner"] !== undefined) {
          contents.Owner = deserializeAws_restXmlOwner(output["Owner"], context);
      }
      if (output["Size"] !== undefined) {
          contents.Size = parseInt(output["Size"]);
      }
      if (output["StorageClass"] !== undefined) {
          contents.StorageClass = output["StorageClass"];
      }
      if (output["VersionId"] !== undefined) {
          contents.VersionId = output["VersionId"];
      }
      return contents;
  };
  var deserializeAws_restXmlObjectVersionList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlObjectVersion(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlOwner = function (output, context) {
      var contents = {
          __type: "Owner",
          DisplayName: undefined,
          ID: undefined
      };
      if (output["DisplayName"] !== undefined) {
          contents.DisplayName = output["DisplayName"];
      }
      if (output["ID"] !== undefined) {
          contents.ID = output["ID"];
      }
      return contents;
  };
  var deserializeAws_restXmlPart = function (output, context) {
      var contents = {
          __type: "Part",
          ETag: undefined,
          LastModified: undefined,
          PartNumber: undefined,
          Size: undefined
      };
      if (output["ETag"] !== undefined) {
          contents.ETag = output["ETag"];
      }
      if (output["LastModified"] !== undefined) {
          contents.LastModified = new Date(output["LastModified"]);
      }
      if (output["PartNumber"] !== undefined) {
          contents.PartNumber = parseInt(output["PartNumber"]);
      }
      if (output["Size"] !== undefined) {
          contents.Size = parseInt(output["Size"]);
      }
      return contents;
  };
  var deserializeAws_restXmlParts = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlPart(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlPolicyStatus = function (output, context) {
      var contents = {
          __type: "PolicyStatus",
          IsPublic: undefined
      };
      if (output["IsPublic"] !== undefined) {
          contents.IsPublic = output["IsPublic"] == "true";
      }
      return contents;
  };
  var deserializeAws_restXmlPublicAccessBlockConfiguration = function (output, context) {
      var contents = {
          __type: "PublicAccessBlockConfiguration",
          BlockPublicAcls: undefined,
          BlockPublicPolicy: undefined,
          IgnorePublicAcls: undefined,
          RestrictPublicBuckets: undefined
      };
      if (output["BlockPublicAcls"] !== undefined) {
          contents.BlockPublicAcls = output["BlockPublicAcls"] == "true";
      }
      if (output["BlockPublicPolicy"] !== undefined) {
          contents.BlockPublicPolicy = output["BlockPublicPolicy"] == "true";
      }
      if (output["IgnorePublicAcls"] !== undefined) {
          contents.IgnorePublicAcls = output["IgnorePublicAcls"] == "true";
      }
      if (output["RestrictPublicBuckets"] !== undefined) {
          contents.RestrictPublicBuckets = output["RestrictPublicBuckets"] == "true";
      }
      return contents;
  };
  var deserializeAws_restXmlQueueConfiguration = function (output, context) {
      var contents = {
          __type: "QueueConfiguration",
          Events: undefined,
          Filter: undefined,
          Id: undefined,
          QueueArn: undefined
      };
      if (output.Event === "") {
          contents.Events = [];
      }
      if (output["Event"] !== undefined) {
          var wrappedItem = output["Event"] instanceof Array ? output["Event"] : [output["Event"]];
          contents.Events = deserializeAws_restXmlEventList(wrappedItem, context);
      }
      if (output["Filter"] !== undefined) {
          contents.Filter = deserializeAws_restXmlNotificationConfigurationFilter(output["Filter"], context);
      }
      if (output["Id"] !== undefined) {
          contents.Id = output["Id"];
      }
      if (output["Queue"] !== undefined) {
          contents.QueueArn = output["Queue"];
      }
      return contents;
  };
  var deserializeAws_restXmlQueueConfigurationList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlQueueConfiguration(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlRedirect = function (output, context) {
      var contents = {
          __type: "Redirect",
          HostName: undefined,
          HttpRedirectCode: undefined,
          Protocol: undefined,
          ReplaceKeyPrefixWith: undefined,
          ReplaceKeyWith: undefined
      };
      if (output["HostName"] !== undefined) {
          contents.HostName = output["HostName"];
      }
      if (output["HttpRedirectCode"] !== undefined) {
          contents.HttpRedirectCode = output["HttpRedirectCode"];
      }
      if (output["Protocol"] !== undefined) {
          contents.Protocol = output["Protocol"];
      }
      if (output["ReplaceKeyPrefixWith"] !== undefined) {
          contents.ReplaceKeyPrefixWith = output["ReplaceKeyPrefixWith"];
      }
      if (output["ReplaceKeyWith"] !== undefined) {
          contents.ReplaceKeyWith = output["ReplaceKeyWith"];
      }
      return contents;
  };
  var deserializeAws_restXmlRedirectAllRequestsTo = function (output, context) {
      var contents = {
          __type: "RedirectAllRequestsTo",
          HostName: undefined,
          Protocol: undefined
      };
      if (output["HostName"] !== undefined) {
          contents.HostName = output["HostName"];
      }
      if (output["Protocol"] !== undefined) {
          contents.Protocol = output["Protocol"];
      }
      return contents;
  };
  var deserializeAws_restXmlReplicationConfiguration = function (output, context) {
      var contents = {
          __type: "ReplicationConfiguration",
          Role: undefined,
          Rules: undefined
      };
      if (output["Role"] !== undefined) {
          contents.Role = output["Role"];
      }
      if (output.Rule === "") {
          contents.Rules = [];
      }
      if (output["Rule"] !== undefined) {
          var wrappedItem = output["Rule"] instanceof Array ? output["Rule"] : [output["Rule"]];
          contents.Rules = deserializeAws_restXmlReplicationRules(wrappedItem, context);
      }
      return contents;
  };
  var deserializeAws_restXmlReplicationRule = function (output, context) {
      var contents = {
          __type: "ReplicationRule",
          DeleteMarkerReplication: undefined,
          Destination: undefined,
          ExistingObjectReplication: undefined,
          Filter: undefined,
          ID: undefined,
          Prefix: undefined,
          Priority: undefined,
          SourceSelectionCriteria: undefined,
          Status: undefined
      };
      if (output["DeleteMarkerReplication"] !== undefined) {
          contents.DeleteMarkerReplication = deserializeAws_restXmlDeleteMarkerReplication(output["DeleteMarkerReplication"], context);
      }
      if (output["Destination"] !== undefined) {
          contents.Destination = deserializeAws_restXmlDestination(output["Destination"], context);
      }
      if (output["ExistingObjectReplication"] !== undefined) {
          contents.ExistingObjectReplication = deserializeAws_restXmlExistingObjectReplication(output["ExistingObjectReplication"], context);
      }
      if (output["Filter"] !== undefined) {
          contents.Filter = deserializeAws_restXmlReplicationRuleFilter(output["Filter"], context);
      }
      if (output["ID"] !== undefined) {
          contents.ID = output["ID"];
      }
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output["Priority"] !== undefined) {
          contents.Priority = parseInt(output["Priority"]);
      }
      if (output["SourceSelectionCriteria"] !== undefined) {
          contents.SourceSelectionCriteria = deserializeAws_restXmlSourceSelectionCriteria(output["SourceSelectionCriteria"], context);
      }
      if (output["Status"] !== undefined) {
          contents.Status = output["Status"];
      }
      return contents;
  };
  var deserializeAws_restXmlReplicationRuleAndOperator = function (output, context) {
      var contents = {
          __type: "ReplicationRuleAndOperator",
          Prefix: undefined,
          Tags: undefined
      };
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output.Tag === "") {
          contents.Tags = [];
      }
      if (output["Tag"] !== undefined) {
          var wrappedItem = output["Tag"] instanceof Array ? output["Tag"] : [output["Tag"]];
          contents.Tags = deserializeAws_restXmlTagSet(wrappedItem, context);
      }
      return contents;
  };
  var deserializeAws_restXmlReplicationRuleFilter = function (output, context) {
      var contents = {
          __type: "ReplicationRuleFilter",
          And: undefined,
          Prefix: undefined,
          Tag: undefined
      };
      if (output["And"] !== undefined) {
          contents.And = deserializeAws_restXmlReplicationRuleAndOperator(output["And"], context);
      }
      if (output["Prefix"] !== undefined) {
          contents.Prefix = output["Prefix"];
      }
      if (output["Tag"] !== undefined) {
          contents.Tag = deserializeAws_restXmlTag(output["Tag"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlReplicationRules = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlReplicationRule(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlReplicationTime = function (output, context) {
      var contents = {
          __type: "ReplicationTime",
          Status: undefined,
          Time: undefined
      };
      if (output["Status"] !== undefined) {
          contents.Status = output["Status"];
      }
      if (output["Time"] !== undefined) {
          contents.Time = deserializeAws_restXmlReplicationTimeValue(output["Time"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlReplicationTimeValue = function (output, context) {
      var contents = {
          __type: "ReplicationTimeValue",
          Minutes: undefined
      };
      if (output["Minutes"] !== undefined) {
          contents.Minutes = parseInt(output["Minutes"]);
      }
      return contents;
  };
  var deserializeAws_restXmlRoutingRule = function (output, context) {
      var contents = {
          __type: "RoutingRule",
          Condition: undefined,
          Redirect: undefined
      };
      if (output["Condition"] !== undefined) {
          contents.Condition = deserializeAws_restXmlCondition(output["Condition"], context);
      }
      if (output["Redirect"] !== undefined) {
          contents.Redirect = deserializeAws_restXmlRedirect(output["Redirect"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlRoutingRules = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlRoutingRule(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlS3KeyFilter = function (output, context) {
      var contents = {
          __type: "S3KeyFilter",
          FilterRules: undefined
      };
      if (output.FilterRule === "") {
          contents.FilterRules = [];
      }
      if (output["FilterRule"] !== undefined) {
          var wrappedItem = output["FilterRule"] instanceof Array
              ? output["FilterRule"]
              : [output["FilterRule"]];
          contents.FilterRules = deserializeAws_restXmlFilterRuleList(wrappedItem, context);
      }
      return contents;
  };
  var deserializeAws_restXmlSSEKMS = function (output, context) {
      var contents = {
          __type: "SSEKMS",
          KeyId: undefined
      };
      if (output["KeyId"] !== undefined) {
          contents.KeyId = output["KeyId"];
      }
      return contents;
  };
  var deserializeAws_restXmlSSES3 = function (output, context) {
      var contents = {
          __type: "SSES3"
      };
      return contents;
  };
  var deserializeAws_restXmlServerSideEncryptionByDefault = function (output, context) {
      var contents = {
          __type: "ServerSideEncryptionByDefault",
          KMSMasterKeyID: undefined,
          SSEAlgorithm: undefined
      };
      if (output["KMSMasterKeyID"] !== undefined) {
          contents.KMSMasterKeyID = output["KMSMasterKeyID"];
      }
      if (output["SSEAlgorithm"] !== undefined) {
          contents.SSEAlgorithm = output["SSEAlgorithm"];
      }
      return contents;
  };
  var deserializeAws_restXmlServerSideEncryptionConfiguration = function (output, context) {
      var contents = {
          __type: "ServerSideEncryptionConfiguration",
          Rules: undefined
      };
      if (output.Rule === "") {
          contents.Rules = [];
      }
      if (output["Rule"] !== undefined) {
          var wrappedItem = output["Rule"] instanceof Array ? output["Rule"] : [output["Rule"]];
          contents.Rules = deserializeAws_restXmlServerSideEncryptionRules(wrappedItem, context);
      }
      return contents;
  };
  var deserializeAws_restXmlServerSideEncryptionRule = function (output, context) {
      var contents = {
          __type: "ServerSideEncryptionRule",
          ApplyServerSideEncryptionByDefault: undefined
      };
      if (output["ApplyServerSideEncryptionByDefault"] !== undefined) {
          contents.ApplyServerSideEncryptionByDefault = deserializeAws_restXmlServerSideEncryptionByDefault(output["ApplyServerSideEncryptionByDefault"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlServerSideEncryptionRules = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlServerSideEncryptionRule(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlSourceSelectionCriteria = function (output, context) {
      var contents = {
          __type: "SourceSelectionCriteria",
          SseKmsEncryptedObjects: undefined
      };
      if (output["SseKmsEncryptedObjects"] !== undefined) {
          contents.SseKmsEncryptedObjects = deserializeAws_restXmlSseKmsEncryptedObjects(output["SseKmsEncryptedObjects"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlSseKmsEncryptedObjects = function (output, context) {
      var contents = {
          __type: "SseKmsEncryptedObjects",
          Status: undefined
      };
      if (output["Status"] !== undefined) {
          contents.Status = output["Status"];
      }
      return contents;
  };
  var deserializeAws_restXmlStorageClassAnalysis = function (output, context) {
      var contents = {
          __type: "StorageClassAnalysis",
          DataExport: undefined
      };
      if (output["DataExport"] !== undefined) {
          contents.DataExport = deserializeAws_restXmlStorageClassAnalysisDataExport(output["DataExport"], context);
      }
      return contents;
  };
  var deserializeAws_restXmlStorageClassAnalysisDataExport = function (output, context) {
      var contents = {
          __type: "StorageClassAnalysisDataExport",
          Destination: undefined,
          OutputSchemaVersion: undefined
      };
      if (output["Destination"] !== undefined) {
          contents.Destination = deserializeAws_restXmlAnalyticsExportDestination(output["Destination"], context);
      }
      if (output["OutputSchemaVersion"] !== undefined) {
          contents.OutputSchemaVersion = output["OutputSchemaVersion"];
      }
      return contents;
  };
  var deserializeAws_restXmlTag = function (output, context) {
      var contents = {
          __type: "Tag",
          Key: undefined,
          Value: undefined
      };
      if (output["Key"] !== undefined) {
          contents.Key = output["Key"];
      }
      if (output["Value"] !== undefined) {
          contents.Value = output["Value"];
      }
      return contents;
  };
  var deserializeAws_restXmlTagSet = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlTag(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlTargetGrant = function (output, context) {
      var contents = {
          __type: "TargetGrant",
          Grantee: undefined,
          Permission: undefined
      };
      if (output["Grantee"] !== undefined) {
          contents.Grantee = deserializeAws_restXmlGrantee(output["Grantee"], context);
      }
      if (output["Permission"] !== undefined) {
          contents.Permission = output["Permission"];
      }
      return contents;
  };
  var deserializeAws_restXmlTargetGrants = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlTargetGrant(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlTopicConfiguration = function (output, context) {
      var contents = {
          __type: "TopicConfiguration",
          Events: undefined,
          Filter: undefined,
          Id: undefined,
          TopicArn: undefined
      };
      if (output.Event === "") {
          contents.Events = [];
      }
      if (output["Event"] !== undefined) {
          var wrappedItem = output["Event"] instanceof Array ? output["Event"] : [output["Event"]];
          contents.Events = deserializeAws_restXmlEventList(wrappedItem, context);
      }
      if (output["Filter"] !== undefined) {
          contents.Filter = deserializeAws_restXmlNotificationConfigurationFilter(output["Filter"], context);
      }
      if (output["Id"] !== undefined) {
          contents.Id = output["Id"];
      }
      if (output["Topic"] !== undefined) {
          contents.TopicArn = output["Topic"];
      }
      return contents;
  };
  var deserializeAws_restXmlTopicConfigurationList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlTopicConfiguration(entry, context));
      });
      return contents;
  };
  var deserializeAws_restXmlTransition = function (output, context) {
      var contents = {
          __type: "Transition",
          Date: undefined,
          Days: undefined,
          StorageClass: undefined
      };
      if (output["Date"] !== undefined) {
          contents.Date = new Date(output["Date"]);
      }
      if (output["Days"] !== undefined) {
          contents.Days = parseInt(output["Days"]);
      }
      if (output["StorageClass"] !== undefined) {
          contents.StorageClass = output["StorageClass"];
      }
      return contents;
  };
  var deserializeAws_restXmlTransitionList = function (output, context) {
      var contents = [];
      (output || []).map(function (entry) {
          contents.push(deserializeAws_restXmlTransition(entry, context));
      });
      return contents;
  };
  var deserializeMetadata = function (output) { return ({
      httpStatusCode: output.statusCode,
      httpHeaders: output.headers,
      requestId: output.headers["x-amzn-requestid"]
  }); };
  // Collect low-level response body stream to Uint8Array.
  var collectBody = function (streamBody, context) {
      if (streamBody instanceof Uint8Array) {
          return Promise.resolve(streamBody);
      }
      return (context.streamCollector(streamBody) || Promise.resolve(new Uint8Array()));
  };
  // Encode Uint8Array data into string with utf-8.
  var collectBodyString = function (streamBody, context) {
      return collectBody(streamBody, context).then(function (body) {
          return context.utf8Encoder(body);
      });
  };
  var decodeEscapedXML = function (str) {
      return str
          .replace(/&amp;/g, "&")
          .replace(/&apos;/g, "'")
          .replace(/&quot;/g, '"')
          .replace(/&gt;/g, ">")
          .replace(/&lt;/g, "<");
  };
  var parseBody = function (streamBody, context) {
      return collectBodyString(streamBody, context).then(function (encoded) {
          if (encoded.length) {
              var parsedObj = xmlParse(encoded, {
                  attributeNamePrefix: "",
                  ignoreAttributes: false,
                  parseNodeValue: false,
                  tagValueProcessor: function (val, tagName) { return decodeEscapedXML(val); }
              });
              var textNodeName = "#text";
              var key = Object.keys(parsedObj)[0];
              var parsedObjToReturn = parsedObj[key];
              if (parsedObjToReturn[textNodeName]) {
                  parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
                  delete parsedObjToReturn[textNodeName];
              }
              return parsedObjToReturn;
          }
          return {};
      });
  };
  var loadRestXmlErrorCode = function (output, data) {
      if (data.Code !== undefined) {
          return data.Code;
      }
      if (output.statusCode == 404) {
          return "NotFound";
      }
      return "";
  };
  //# sourceMappingURL=Aws_restXml.js.map