1 line
10 KiB
JSON
1 line
10 KiB
JSON
|
{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.writeProtobufMessage = exports.MessageWriter = void 0;\nconst util_js_1 = require(\"./util.js\");\nclass MessageWriter {\n #buf;\n #array;\n #view;\n #pos;\n constructor() {\n this.#buf = new ArrayBuffer(256);\n this.#array = new Uint8Array(this.#buf);\n this.#view = new DataView(this.#buf);\n this.#pos = 0;\n }\n #ensure(extra) {\n if (this.#pos + extra <= this.#buf.byteLength) {\n return;\n }\n let newCap = this.#buf.byteLength;\n while (newCap < this.#pos + extra) {\n newCap *= 2;\n }\n const newBuf = new ArrayBuffer(newCap);\n const newArray = new Uint8Array(newBuf);\n const newView = new DataView(newBuf);\n newArray.set(new Uint8Array(this.#buf, 0, this.#pos));\n this.#buf = newBuf;\n this.#array = newArray;\n this.#view = newView;\n }\n #varint(value) {\n this.#ensure(5);\n value = 0 | value;\n do {\n let byte = value & 0x7f;\n value >>>= 7;\n byte |= value ? 0x80 : 0;\n this.#array[this.#pos++] = byte;\n } while (value);\n }\n #varintBig(value) {\n this.#ensure(10);\n value = value & 0xffffffffffffffffn;\n do {\n let byte = Number(value & 0x7fn);\n value >>= 7n;\n byte |= value ? 0x80 : 0;\n this.#array[this.#pos++] = byte;\n } while (value);\n }\n #tag(tag, wireType) {\n this.#varint(tag << 3 | wireType);\n }\n bytes(tag, value) {\n this.#tag(tag, util_js_1.LENGTH_DELIMITED);\n this.#varint(value.byteLength);\n this.#ensure(value.byteLength);\n this.#array.set(value, this.#pos);\n this.#pos += value.byteLength;\n }\n string(tag, value) {\n this.bytes(tag, new TextEncoder().encode(value));\n }\n message(tag, value, fun) {\n const writer = new MessageWriter();\n fun(writer, value);\n this.bytes(tag, writer.data());\n }\n int32(tag, value) {\n this.#tag(tag, util_js_1.VARINT);\n this.#varint(value);\n }\n uint32(tag, value) {\n this.int32(tag, value);\n }\n bool(tag, value) {\n this.int32(tag, value ? 1 : 0);\n }\n sint64(tag, value) {\n this.#tag(tag, util_js_1.VARINT);\n this.#varintBig(value << 1n ^ value >> 63n);\n }\n double(tag, value) {\n this.#tag(tag, util_js_1.FIXED_64);\n this.#ensure(8);\n this.#view.setFloat64(this.#pos, value, true);\n this.#pos += 8;\n }\n data() {\n return new Uint8Array(this.#buf, 0, this.#pos);\n }\n}\nexports.MessageWriter = MessageWriter;\nfunction writeProtobufMessage(value, fun) {\n const w = new MessageWriter();\n fun(w, value);\n return w.data();\n}\nexports.writeProtobufMessage = writeProtobufMessage;","map":{"version":3,"names":["Object","defineProperty","exports","value","writeProtobufMessage","MessageWriter","util_js_1","require","buf","array","view","pos","constructor","ArrayBuffer","Uint8Array","DataView","ensure","#ensure","extra","byteLength","newCap","newBuf","newArray","newView","set","varint","#varint","byte","varintBig","#varintBig","Number","tag","#tag","wireType","bytes","LENGTH_DELIMITED","string","TextEncoder","encode","message","fun","writer","data","int32","VARINT","uint32","bool","sint64","double","FIXED_64","setFloat64","w"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-cjs/encoding/protobuf/encode.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.writeProtobufMessage = exports.MessageWriter = void 0;\nconst util_js_1 = require(\"./util.js\");\nclass MessageWriter {\n #buf;\n #array;\n #view;\n #pos;\n constructor() {\n this.#buf = new ArrayBuffer(256);\n this.#array = new Uint8Array(this.#buf);\n this.#view = new DataView(this.#buf);\n this.#pos = 0;\n }\n #ensure(extra) {\n if (this.#pos + extra <= this.#buf.byteLength) {\n return;\n }\n let newCap = this.#buf.byteLength;\n while (newCap < this.#pos + extra) {\n newCap *= 2
|