UNPKG

@azure/cosmos

Version:
48 lines (47 loc) 2.09 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var string_exports = {}; __export(string_exports, { writeStringForBinaryEncoding: () => writeStringForBinaryEncoding }); module.exports = __toCommonJS(string_exports); var import_prefix = require("./prefix.js"); var import_uint8 = require("../../uint8.js"); function writeStringForBinaryEncoding(payload) { const outputStream = (0, import_uint8.hexStringToUint8Array)(import_prefix.BytePrefix.String); const MAX_STRING_BYTES_TO_APPEND = 100; const byteArray = new TextEncoder().encode(payload); const isShortString = payload.length <= MAX_STRING_BYTES_TO_APPEND; let finalStream = outputStream; for (let index = 0; index < (isShortString ? byteArray.length : MAX_STRING_BYTES_TO_APPEND + 1); index++) { let charByte = byteArray[index]; if (charByte < 255) { charByte++; } const hexRep = charByte.toString(16).padStart(2, "0"); finalStream = (0, import_uint8.concatUint8Arrays)([finalStream, (0, import_uint8.hexStringToUint8Array)(hexRep)]); } if (isShortString) { finalStream = (0, import_uint8.concatUint8Arrays)([finalStream, (0, import_uint8.hexStringToUint8Array)(import_prefix.BytePrefix.Undefined)]); } return finalStream; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { writeStringForBinaryEncoding });