var v = Object.defineProperty;
var a = (t, r) => v(t, "name", { value: r, configurable: !0 });
import { ConnectError as c } from "../connect-error.js";
import { Code as s } from "../code.js";
function w(t) {
  var r;
  const e = Object.assign({}, t);
  return (r = e.ignoreUnknownFields) !== null && r !== void 0 || (e.ignoreUnknownFields = !0), e;
}
a(w, "getJsonOptions");
function y(t, r, e, n) {
  const o = r ? f(t.I, n) : g(t.I, e);
  return { parse: (r ? f(t.O, n) : g(t.O, e)).parse, serialize: o.serialize };
}
a(y, "createClientMethodSerializers");
function f(t, r) {
  return {
    parse(e) {
      try {
        return t.fromBinary(e, r);
      } catch (n) {
        const o = n instanceof Error ? n.message : String(n);
        throw new c(`parse binary: ${o}`, s.Internal);
      }
    },
    serialize(e) {
      try {
        return e.toBinary(r);
      } catch (n) {
        const o = n instanceof Error ? n.message : String(n);
        throw new c(`serialize binary: ${o}`, s.Internal);
      }
    }
  };
}
a(f, "createBinarySerialization");
function g(t, r) {
  var e, n;
  const o = (e = r?.textEncoder) !== null && e !== void 0 ? e : new TextEncoder(), u = (n = r?.textDecoder) !== null && n !== void 0 ? n : new TextDecoder(), d = w(r);
  return {
    parse(l) {
      try {
        const i = u.decode(l);
        return t.fromJsonString(i, d);
      } catch (i) {
        throw c.from(i, s.InvalidArgument);
      }
    },
    serialize(l) {
      try {
        const i = l.toJsonString(d);
        return o.encode(i);
      } catch (i) {
        throw c.from(i, s.Internal);
      }
    }
  };
}
a(g, "createJsonSerialization");
export {
  f as createBinarySerialization,
  y as createClientMethodSerializers,
  g as createJsonSerialization,
  w as getJsonOptions
};
