1 line
9.4 KiB
JSON
1 line
9.4 KiB
JSON
{"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 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}\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,QAAQ,EAAEC,gBAAgB,QAAQ,WAAW;AAC9D,OAAO,MAAMC,aAAa,CAAC;EACvB,CAACC,GAAG;EACJ,CAACC,KAAK;EACN,CAACC,IAAI;EACL,CAACC,GAAG;EACJC,WAAWA,CAAA,EAAG;IACV,IAAI,CAAC,CAACJ,GAAG,GAAG,IAAIK,WAAW,CAAC,GAAG,CAAC;IAChC,IAAI,CAAC,CAACJ,KAAK,GAAG,IAAIK,UAAU,CAAC,IAAI,CAAC,CAACN,GAAG,CAAC;IACvC,IAAI,CAAC,CAACE,IAAI,GAAG,IAAIK,QAAQ,CAAC,IAAI,CAAC,CAACP,GAAG,CAAC;IACpC,IAAI,CAAC,CAACG,GAAG,GAAG,CAAC;EACjB;EACA,CAACK,MAAMC,CAACC,KAAK,EAAE;IACX,IAAI,IAAI,C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