var m = Object.defineProperty;
var d = (t, e) => m(t, "name", { value: e, configurable: !0 });
import { assert as w } from "./private/assert.js";
import { filterUnknownFields as b, createExtensionContainer as k } from "./private/extensions.js";
function U(t, e, o) {
  u(e, t);
  const r = e.runtime.bin.makeReadOptions(o), l = b(t.getType().runtime.bin.listUnknownFields(t), e.field), [p, a] = k(e);
  for (const n of l)
    e.runtime.bin.readField(p, r.readerFactory(n.data), e.field, n.wireType, r);
  return a();
}
d(U, "getExtension");
function N(t, e, o, r) {
  u(e, t);
  const l = e.runtime.bin.makeReadOptions(r), p = e.runtime.bin.makeWriteOptions(r);
  if (F(t, e)) {
    const f = t.getType().runtime.bin.listUnknownFields(t).filter((i) => i.no != e.field.no);
    t.getType().runtime.bin.discardUnknownFields(t);
    for (const i of f)
      t.getType().runtime.bin.onUnknownField(t, i.no, i.wireType, i.data);
  }
  const a = p.writerFactory();
  let n = e.field;
  !n.opt && !n.repeated && (n.kind == "enum" || n.kind == "scalar") && (n = Object.assign(Object.assign({}, e.field), { opt: !0 })), e.runtime.bin.writeField(n, o, a, p);
  const c = l.readerFactory(a.finish());
  for (; c.pos < c.len; ) {
    const [f, i] = c.tag(), y = c.skip(i, f);
    t.getType().runtime.bin.onUnknownField(t, f, i, y);
  }
}
d(N, "setExtension");
function F(t, e) {
  const o = t.getType();
  return e.extendee.typeName === o.typeName && !!o.runtime.bin.listUnknownFields(t).find((r) => r.no == e.field.no);
}
d(F, "hasExtension");
function u(t, e) {
  w(t.extendee.typeName == e.getType().typeName, `extension ${t.typeName} can only be applied to message ${t.extendee.typeName}`);
}
d(u, "assertExtendee");
export {
  U as getExtension,
  F as hasExtension,
  N as setExtension
};
