the-forest/client/node_modules/.cache/babel-loader/a4ab23b318cf0100c37850107f2d77c18b8f7727dc53f236ecabbd8b6136a476.json

1 line
9.4 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"import { VARINT, FIXED_64, LENGTH_DELIMITED } from \"./util.js\";\nexport class 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, 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, 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, VARINT);\n this.#varintBig(value << 1n ^ value >> 63n);\n }\n double(tag, value) {\n this.#tag(tag, 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}\nexport function writeProtobufMessage(value, fun) {\n const w = new MessageWriter();\n fun(w, value);\n return w.data();\n}","map":{"version":3,"names":["VARINT","FIXED_64","LENGTH_DELIMITED","MessageWriter","buf","array","view","pos","constructor","ArrayBuffer","Uint8Array","DataView","ensure","#ensure","extra","byteLength","newCap","newBuf","newArray","newView","set","varint","#varint","value","byte","varintBig","#varintBig","Number","tag","#tag","wireType","bytes","string","TextEncoder","encode","message","fun","writer","data","int32","uint32","bool","sint64","double","setFloat64","writeProtobufMessage","w"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-esm/encoding/protobuf/encode.js"],"sourcesContent":["import { VARINT, FIXED_64, LENGTH_DELIMITED } from \"./util.js\";\nexport class 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