aws-crt
Version:
NodeJS/browser bindings to the aws-c-* libraries
46 lines • 1.42 kB
JavaScript
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_KEEP_ALIVE = exports.normalize_payload = void 0;
/**
* @packageDocumentation
*/
/**
* Converts payload to Buffer or string regardless of the supplied type
* @param payload The payload to convert
* @internal
*/
function normalize_payload(payload) {
if (payload instanceof Buffer) {
// pass Buffer through
return payload;
}
if (typeof payload === 'string') {
// pass string through
return payload;
}
if (ArrayBuffer.isView(payload)) {
// return Buffer with view upon the same bytes (no copy)
const view = payload;
return Buffer.from(view.buffer, view.byteOffset, view.byteLength);
}
if (payload instanceof ArrayBuffer) {
// return Buffer with view upon the same bytes (no copy)
return Buffer.from(payload);
}
if (typeof payload === 'object') {
// Convert Object to JSON string
return JSON.stringify(payload);
}
if (!payload) {
return "";
}
throw new TypeError("payload parameter must be a string, object, or DataView.");
}
exports.normalize_payload = normalize_payload;
/** @internal */
exports.DEFAULT_KEEP_ALIVE = 1200;
//# sourceMappingURL=mqtt_shared.js.map
;