{"ast":null,"code":"import { ProtoError } from \"../../errors.js\";\nimport { VARINT, FIXED_64, LENGTH_DELIMITED, FIXED_32 } from \"./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}\nexport class 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 ProtoError(`Expected wire type ${expectedWireType}, got ${this.#wireType}`);\n }\n this.#wireType = -1;\n }\n bytes() {\n this.#expect(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(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(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(FIXED_64);\n return this.#reader.double();\n }\n maybeSkip() {\n if (this.#wireType < 0) {\n return;\n } else if (this.#wireType === VARINT) {\n this.#reader.skipVarint();\n } else if (this.#wireType === FIXED_64) {\n this.#reader.skip(8);\n } else if (this.#wireType === LENGTH_DELIMITED) {\n const length = this.#reader.varint();\n this.#reader.skip(length);\n } else if (this.#wireType === FIXED_32) {\n this.#reader.skip(4);\n } else {\n throw new ProtoError(`Unexpected wire type ${this.#wireType}`);\n }\n this.#wireType = -1;\n }\n}\nexport function 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}","map":{"version":3,"names":["ProtoError","VARINT","FIXED_64","LENGTH_DELIMITED","FIXED_32","MessageReader","array","view","pos","constructor","DataView","buffer","byteOffset","byteLength","varint","value","shift","byte","varintBig","BigInt","bytes","length","Uint8Array","double","getFloat64","skipVarint","skip","count","eof","FieldReader","reader","wireType","setup","expect","#expect","expectedWireType","string","TextDecoder","decode","message","def","readProtobufMessage","int32","uint32","bool","uint64","sint64","maybeSkip","data","msgReader","fieldReader","default","key","tag","tagFun","undefined","returnedValue"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-esm/encoding/protobuf/decode.js"],"sourcesContent":["import { ProtoError } from \"../../errors.js\";\nimport { VARINT, FIXED_64, LENGTH_DELIMITED, FIXED_32 } from \"./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}\nexport class 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 ProtoError(`Expected wire type ${expectedWireType}, got ${this.#wireType}`);\n }\n this.#wireType = -1;\n }\n bytes() {\n this.#expect(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(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(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(FIXED_64);\n return this.#reader.double();\n }\n maybeSkip() {\n if (this.#wireType < 0) {\n return;\n }\n else if (this.#wireType === VARINT) {\n this.#reader.skipVarint();\n }\n else if (this.#wireType === FIXED_64) {\n this.#reader.skip(8);\n }\n else if (this.#wireType === LENGTH_DELIMITED) {\n const length = this.#reader.varint();\n this.#reader.skip(length);\n }\n else if (this.#wireType === FIXED_32) {\n this.#reader.skip(4);\n }\n else {\n throw new ProtoError(`Unexpected wire type ${this.#wireType}`);\n }\n this.#wireType = -1;\n }\n}\nexport function 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}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,MAAM,EAAEC,QAAQ,EAAEC,gBAAgB,EAAEC,QAAQ,QAAQ,WAAW;AACxE,MAAMC,aAAa,CAAC;EAChB,CAACC,KAAK;EACN,CAACC,IAAI;EACL,CAACC,GAAG;EACJC,WAAWA,CAACH,KAAK,EAAE;IACf,IAAI,CAAC,CAACA,KAAK,GAAGA,KAAK;IACnB,IAAI,CAAC,CAACC,IAAI,GAAG,IAAIG,QAAQ,CAACJ,KAAK,CAACK,MAAM,EAAEL,KAAK,CAACM,UAAU,EAAEN,KAAK,CAACO,UAAU,CAAC;IAC3E,IAAI,CAAC,CAACL,GAAG,GAAG,CAAC;EACjB;EACAM,MAAMA,CAAA,EAAG;IACL,IAAIC,KAAK,GAAG,CAAC;IACb,KAAK,IAAIC,KAAK,GAAG,CAAC,GAAGA,KAAK,IAAI,CAAC,EAAE;MAC7B,MAAMC,IAAI,GAAG,IAAI,CAAC,CAACX,KAAK,CAAC,IAAI,CAAC,CAACE,GAAG,EAAE,CAAC;MACrCO,KAAK,IAAI,CAACE,IAAI,GAAG,IAAI,KAA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