import { __commonJSMin as e } from "../../../../_virtual/_rolldown/runtime.js";
//#region ../../node_modules/vscode-jsonrpc/lib/common/messageBuffer.js
var t = /* @__PURE__ */ e(((e) => {
	Object.defineProperty(e, "__esModule", { value: !0 }), e.AbstractMessageBuffer = void 0;
	var t = 13, n = 10, r = "\r\n";
	e.AbstractMessageBuffer = class {
		constructor(e = "utf-8") {
			this._encoding = e, this._chunks = [], this._totalLength = 0;
		}
		get encoding() {
			return this._encoding;
		}
		append(e) {
			let t = typeof e == "string" ? this.fromString(e, this._encoding) : e;
			this._chunks.push(t), this._totalLength += t.byteLength;
		}
		tryReadHeaders(e = !1) {
			if (this._chunks.length === 0) return;
			let i = 0, a = 0, o = 0, s = 0;
			row: for (; a < this._chunks.length;) {
				let e = this._chunks[a];
				o = 0;
				column: for (; o < e.length;) {
					switch (e[o]) {
						case t:
							switch (i) {
								case 0:
									i = 1;
									break;
								case 2:
									i = 3;
									break;
								default: i = 0;
							}
							break;
						case n:
							switch (i) {
								case 1:
									i = 2;
									break;
								case 3:
									i = 4, o++;
									break row;
								default: i = 0;
							}
							break;
						default: i = 0;
					}
					o++;
				}
				s += e.byteLength, a++;
			}
			if (i !== 4) return;
			let c = this._read(s + o), l = /* @__PURE__ */ new Map(), u = this.toString(c, "ascii").split(r);
			if (u.length < 2) return l;
			for (let t = 0; t < u.length - 2; t++) {
				let n = u[t], r = n.indexOf(":");
				if (r === -1) throw Error(`Message header must separate key and value using ':'\n${n}`);
				let i = n.substr(0, r), a = n.substr(r + 1).trim();
				l.set(e ? i.toLowerCase() : i, a);
			}
			return l;
		}
		tryReadBody(e) {
			if (!(this._totalLength < e)) return this._read(e);
		}
		get numberOfBytes() {
			return this._totalLength;
		}
		_read(e) {
			if (e === 0) return this.emptyBuffer();
			if (e > this._totalLength) throw Error("Cannot read so many bytes!");
			if (this._chunks[0].byteLength === e) {
				let t = this._chunks[0];
				return this._chunks.shift(), this._totalLength -= e, this.asNative(t);
			}
			if (this._chunks[0].byteLength > e) {
				let t = this._chunks[0], n = this.asNative(t, e);
				return this._chunks[0] = t.slice(e), this._totalLength -= e, n;
			}
			let t = this.allocNative(e), n = 0;
			for (; e > 0;) {
				let r = this._chunks[0];
				if (r.byteLength > e) {
					let i = r.slice(0, e);
					t.set(i, n), n += e, this._chunks[0] = r.slice(e), this._totalLength -= e, e -= e;
				} else t.set(r, n), n += r.byteLength, this._chunks.shift(), this._totalLength -= r.byteLength, e -= r.byteLength;
			}
			return t;
		}
	};
}));
//#endregion
export default t();
export { t as require_messageBuffer };
