1 line
14 KiB
JSON
1 line
14 KiB
JSON
{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.readProtobufMessage = exports.FieldReader = void 0;\nconst errors_js_1 = require(\"../../errors.js\");\nconst util_js_1 = require(\"./util.js\");\nclass MessageReader {\n #array;\n #view;\n #pos;\n constructor(array) {\n this.#array = array;\n this.#view = new DataView(array.buffer, array.byteOffset, array.byteLength);\n this.#pos = 0;\n }\n varint() {\n let value = 0;\n for (let shift = 0;; shift += 7) {\n const byte = this.#array[this.#pos++];\n value |= (byte & 0x7f) << shift;\n if (!(byte & 0x80)) {\n break;\n }\n }\n return value;\n }\n varintBig() {\n let value = 0n;\n for (let shift = 0n;; shift += 7n) {\n const byte = this.#array[this.#pos++];\n value |= BigInt(byte & 0x7f) << shift;\n if (!(byte & 0x80)) {\n break;\n }\n }\n return value;\n }\n bytes(length) {\n const array = new Uint8Array(this.#array.buffer, this.#array.byteOffset + this.#pos, length);\n this.#pos += length;\n return array;\n }\n double() {\n const value = this.#view.getFloat64(this.#pos, true);\n this.#pos += 8;\n return value;\n }\n skipVarint() {\n for (;;) {\n const byte = this.#array[this.#pos++];\n if (!(byte & 0x80)) {\n break;\n }\n }\n }\n skip(count) {\n this.#pos += count;\n }\n eof() {\n return this.#pos >= this.#array.byteLength;\n }\n}\nclass FieldReader {\n #reader;\n #wireType;\n constructor(reader) {\n this.#reader = reader;\n this.#wireType = -1;\n }\n setup(wireType) {\n this.#wireType = wireType;\n }\n #expect(expectedWireType) {\n if (this.#wireType !== expectedWireType) {\n throw new errors_js_1.ProtoError(`Expected wire type ${expectedWireType}, got ${this.#wireType}`);\n }\n this.#wireType = -1;\n }\n bytes() {\n this.#expect(util_js_1.LENGTH_DELIMITED);\n const length = this.#reader.varint();\n return this.#reader.bytes(length);\n }\n string() {\n return new TextDecoder().decode(this.bytes());\n }\n message(def) {\n return readProtobufMessage(this.bytes(), def);\n }\n int32() {\n this.#expect(util_js_1.VARINT);\n return this.#reader.varint();\n }\n uint32() {\n return this.int32();\n }\n bool() {\n return this.int32() !== 0;\n }\n uint64() {\n this.#expect(util_js_1.VARINT);\n return this.#reader.varintBig();\n }\n sint64() {\n const value = this.uint64();\n return value >> 1n ^ -(value & 1n);\n }\n double() {\n this.#expect(util_js_1.FIXED_64);\n return this.#reader.double();\n }\n maybeSkip() {\n if (this.#wireType < 0) {\n return;\n } else if (this.#wireType === util_js_1.VARINT) {\n this.#reader.skipVarint();\n } else if (this.#wireType === util_js_1.FIXED_64) {\n this.#reader.skip(8);\n } else if (this.#wireType === util_js_1.LENGTH_DELIMITED) {\n const length = this.#reader.varint();\n this.#reader.skip(length);\n } else if (this.#wireType === util_js_1.FIXED_32) {\n this.#reader.skip(4);\n } else {\n throw new errors_js_1.ProtoError(`Unexpected wire type ${this.#wireType}`);\n }\n this.#wireType = -1;\n }\n}\nexports.FieldReader = FieldReader;\nfunction readProtobufMessage(data, def) {\n const msgReader = new MessageReader(data);\n const fieldReader = new FieldReader(msgReader);\n let value = def.default();\n while (!msgReader.eof()) {\n const key = msgReader.varint();\n const tag = key >> 3;\n const wireType = key & 0x7;\n fieldReader.setup(wireType);\n const tagFun = def[tag];\n if (tagFun !== undefined) {\n const returnedValue = tagFun(fieldReader, value);\n if (returnedValue !== undefined) {\n value = returnedValue;\n }\n }\n fieldReader.maybeSkip();\n }\n return value;\n}\nexports.readProtobufMessage = readProtobufMessage;","map":{"version":3,"names":["Object","defineProperty","exports","value","readProtobufMessage","FieldReader","errors_js_1","require","util_js_1","MessageReader","array","view","pos","constructor","DataView","buffer","byteOffset","byteLength","varint","shift","byte","varintBig","BigInt","bytes","length","Uint8Array","double","getFloat64","skipVarint","skip","count","eof","reader","wireType","setup","expect","#expect","expectedWireType","ProtoError","LENGTH_DELIMITED","string","TextDecoder","decode","message","def","int32","VARINT","uint32","bool","uint64","sint64","FIXED_64","maybeSkip","FIXED_32","data","msgReader","fieldReader","default","key","tag","tagFun","undefined","returnedValue"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-cjs/encoding/protobuf/decode.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.readProtobufMessage = exports.FieldReader = void 0;\nconst errors_js_1 = require(\"../../errors.js\");\nconst util_js_1 = require(\"./util.js\");\nclass MessageReader {\n #array;\n #view;\n #pos;\n constructor(array) {\n this.#array = array;\n this.#view = new DataView(array.buffer, array.byteOffset, array.byteLength);\n this.#pos = 0;\n }\n varint() {\n let value = 0;\n for (let shift = 0;; shift += 7) {\n const byte = this.#array[this.#pos++];\n value |= (byte & 0x7f) << shift;\n if (!(byte & 0x80)) {\n break;\n }\n }\n return value;\n }\n varintBig() {\n let value = 0n;\n for (let shift = 0n;; shift += 7n) {\n const byte = this.#array[this.#pos++];\n value |= BigInt(byte & 0x7f) << shift;\n if (!(byte & 0x80)) {\n break;\n }\n }\n return value;\n }\n bytes(length) {\n const array = new Uint8Array(this.#array.buffer, this.#array.byteOffset + this.#pos, length);\n this.#pos += length;\n return array;\n }\n double() {\n const value = this.#view.getFloat64(this.#pos, true);\n this.#pos += 8;\n return value;\n }\n skipVarint() {\n for (;;) {\n const byte = this.#array[this.#pos++];\n if (!(byte & 0x80)) {\n break;\n }\n }\n }\n skip(count) {\n this.#pos += count;\n }\n eof() {\n return this.#pos >= this.#array.byteLength;\n }\n}\nclass FieldReader {\n #reader;\n #wireType;\n constructor(reader) {\n this.#reader = reader;\n this.#wireType = -1;\n }\n setup(wireType) {\n this.#wireType = wireType;\n }\n #expect(expectedWireType) {\n if (this.#wireType !== expectedWireType) {\n throw new errors_js_1.ProtoError(`Expected wire type ${expectedWireType}, got ${this.#wireType}`);\n }\n this.#wireType = -1;\n }\n bytes() {\n this.#expect(util_js_1.LENGTH_DELIMITED);\n const length = this.#reader.varint();\n return this.#reader.bytes(length);\n }\n string() {\n return new TextDecoder().decode(this.bytes());\n }\n message(def) {\n return readProtobufMessage(this.bytes(), def);\n }\n int32() {\n this.#expect(util_js_1.VARINT);\n return this.#reader.varint();\n }\n uint32() {\n return this.int32();\n }\n bool() {\n return this.int32() !== 0;\n }\n uint64() {\n this.#expect(util_js_1.VARINT);\n return this.#reader.varintBig();\n }\n sint64() {\n const value = this.uint64();\n return (value >> 1n) ^ (-(value & 1n));\n }\n double() {\n this.#expect(util_js_1.FIXED_64);\n return this.#reader.double();\n }\n maybeSkip() {\n if (this.#wireType < 0) {\n return;\n }\n else if (this.#wireType === util_js_1.VARINT) {\n this.#reader.skipVarint();\n }\n else if (this.#wireType === util_js_1.FIXED_64) {\n this.#reader.skip(8);\n }\n else if (this.#wireType === util_js_1.LENGTH_DELIMITED) {\n const length = this.#reader.varint();\n this.#reader.skip(length);\n }\n else if (this.#wireType === util_js_1.FIXED_32) {\n this.#reader.skip(4);\n }\n else {\n throw new errors_js_1.ProtoError(`Unexpected wire type ${this.#wireType}`);\n }\n this.#wireType = -1;\n }\n}\nexports.FieldReader = FieldReader;\nfunction readProtobufMessage(data, def) {\n const msgReader = new MessageReader(data);\n const fieldReader = new FieldReader(msgReader);\n let value = def.default();\n while (!msgReader.eof()) {\n const key = msgReader.varint();\n const tag = key >> 3;\n const wireType = key & 0x7;\n fieldReader.setup(wireType);\n const tagFun = def[tag];\n if (tagFun !== undefined) {\n const returnedValue = tagFun(fieldReader, value);\n if (returnedValue !== undefined) {\n value = returnedValue;\n }\n }\n fieldReader.maybeSkip();\n }\n return value;\n}\nexports.readProtobufMessage = readProtobufMessage;\n"],"mappings":"AAAA,YAAY;;AACZA,MAAM,CAACC,cAAc,CAACC,OAAO,EAAE,YAAY,EAAE;EAAEC,KAAK,EAAE;AAAK,CAAC,CAAC;AAC7DD,OAAO,CAACE,mBAAmB,GAAGF,OAAO,CAACG,WAAW,GAAG,KAAK,CAAC;AAC1D,MAAMC,WAAW,GAAGC,OAAO,CAAC,iBAAiB,CAAC;AAC9C,MAAMC,SAAS,GAAGD,OAAO,CAAC,WAAW,CAAC;AACtC,MA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