var d = Object.defineProperty;
var f = (t, i) => d(t, "name", { value: i, configurable: !0 });
function B() {
  let t = 0, i = 0;
  for (let n = 0; n < 28; n += 7) {
    let r = this.buf[this.pos++];
    if (t |= (r & 127) << n, !(r & 128))
      return this.assertBounds(), [t, i];
  }
  let s = this.buf[this.pos++];
  if (t |= (s & 15) << 28, i = (s & 112) >> 4, !(s & 128))
    return this.assertBounds(), [t, i];
  for (let n = 3; n <= 31; n += 7) {
    let r = this.buf[this.pos++];
    if (i |= (r & 127) << n, !(r & 128))
      return this.assertBounds(), [t, i];
  }
  throw new Error("invalid varint");
}
f(B, "varint64read");
function b(t, i, s) {
  for (let e = 0; e < 28; e = e + 7) {
    const o = t >>> e, h = !(!(o >>> 7) && i == 0), u = (h ? o | 128 : o) & 255;
    if (s.push(u), !h)
      return;
  }
  const n = t >>> 28 & 15 | (i & 7) << 4, r = !!(i >> 3);
  if (s.push((r ? n | 128 : n) & 255), !!r) {
    for (let e = 3; e < 31; e = e + 7) {
      const o = i >>> e, h = !!(o >>> 7), u = (h ? o | 128 : o) & 255;
      if (s.push(u), !h)
        return;
    }
    s.push(i >>> 31 & 1);
  }
}
f(b, "varint64write");
const x = 4294967296;
function w(t) {
  const i = t[0] === "-";
  i && (t = t.slice(1));
  const s = 1e6;
  let n = 0, r = 0;
  function e(o, h) {
    const u = Number(t.slice(o, h));
    r *= s, n = n * s + u, n >= x && (r = r + (n / x | 0), n = n % x);
  }
  return f(e, "add1e6digit"), e(-24, -18), e(-18, -12), e(-12, -6), e(-6), i ? a(n, r) : c(n, r);
}
f(w, "int64FromString");
function m(t, i) {
  let s = c(t, i);
  const n = s.hi & 2147483648;
  n && (s = a(s.lo, s.hi));
  const r = F(s.lo, s.hi);
  return n ? "-" + r : r;
}
f(m, "int64ToString");
function F(t, i) {
  if ({ lo: t, hi: i } = p(t, i), i <= 2097151)
    return String(x * i + t);
  const s = t & 16777215, n = (t >>> 24 | i << 8) & 16777215, r = i >> 16 & 65535;
  let e = s + n * 6777216 + r * 6710656, o = n + r * 8147497, h = r * 2;
  const u = 1e7;
  return e >= u && (o += Math.floor(e / u), e %= u), o >= u && (h += Math.floor(o / u), o %= u), h.toString() + l(o) + l(e);
}
f(F, "uInt64ToString");
function p(t, i) {
  return { lo: t >>> 0, hi: i >>> 0 };
}
f(p, "toUnsigned");
function c(t, i) {
  return { lo: t | 0, hi: i | 0 };
}
f(c, "newBits");
function a(t, i) {
  return i = ~i, t ? t = ~t + 1 : i += 1, c(t, i);
}
f(a, "negate");
const l = /* @__PURE__ */ f((t) => {
  const i = String(t);
  return "0000000".slice(i.length) + i;
}, "decimalFrom1e7WithLeadingZeros");
function S(t, i) {
  if (t >= 0) {
    for (; t > 127; )
      i.push(t & 127 | 128), t = t >>> 7;
    i.push(t);
  } else {
    for (let s = 0; s < 9; s++)
      i.push(t & 127 | 128), t = t >> 7;
    i.push(1);
  }
}
f(S, "varint32write");
function M() {
  let t = this.buf[this.pos++], i = t & 127;
  if (!(t & 128))
    return this.assertBounds(), i;
  if (t = this.buf[this.pos++], i |= (t & 127) << 7, !(t & 128))
    return this.assertBounds(), i;
  if (t = this.buf[this.pos++], i |= (t & 127) << 14, !(t & 128))
    return this.assertBounds(), i;
  if (t = this.buf[this.pos++], i |= (t & 127) << 21, !(t & 128))
    return this.assertBounds(), i;
  t = this.buf[this.pos++], i |= (t & 15) << 28;
  for (let s = 5; t & 128 && s < 10; s++)
    t = this.buf[this.pos++];
  if (t & 128)
    throw new Error("invalid varint");
  return this.assertBounds(), i >>> 0;
}
f(M, "varint32read");
export {
  w as int64FromString,
  m as int64ToString,
  F as uInt64ToString,
  M as varint32read,
  S as varint32write,
  B as varint64read,
  b as varint64write
};
