var a = Object.defineProperty;
var o = (i, t) => a(i, "name", { value: t, configurable: !0 });
class h {
  static {
    o(this, "Message");
  }
  /**
   * Compare with a message of the same type.
   * Note that this function disregards extensions and unknown fields.
   */
  equals(t) {
    return this.getType().runtime.util.equals(this.getType(), this, t);
  }
  /**
   * Create a deep copy.
   */
  clone() {
    return this.getType().runtime.util.clone(this);
  }
  /**
   * Parse from binary data, merging fields.
   *
   * Repeated fields are appended. Map entries are added, overwriting
   * existing keys.
   *
   * If a message field is already present, it will be merged with the
   * new data.
   */
  fromBinary(t, s) {
    const e = this.getType(), r = e.runtime.bin, n = r.makeReadOptions(s);
    return r.readMessage(this, n.readerFactory(t), t.byteLength, n), this;
  }
  /**
   * Parse a message from a JSON value.
   */
  fromJson(t, s) {
    const e = this.getType(), r = e.runtime.json, n = r.makeReadOptions(s);
    return r.readMessage(e, t, n, this), this;
  }
  /**
   * Parse a message from a JSON string.
   */
  fromJsonString(t, s) {
    let e;
    try {
      e = JSON.parse(t);
    } catch (r) {
      throw new Error(`cannot decode ${this.getType().typeName} from JSON: ${r instanceof Error ? r.message : String(r)}`);
    }
    return this.fromJson(e, s);
  }
  /**
   * Serialize the message to binary data.
   */
  toBinary(t) {
    const s = this.getType(), e = s.runtime.bin, r = e.makeWriteOptions(t), n = r.writerFactory();
    return e.writeMessage(this, n, r), n.finish();
  }
  /**
   * Serialize the message to a JSON value, a JavaScript value that can be
   * passed to JSON.stringify().
   */
  toJson(t) {
    const s = this.getType(), e = s.runtime.json, r = e.makeWriteOptions(t);
    return e.writeMessage(this, r);
  }
  /**
   * Serialize the message to a JSON string.
   */
  toJsonString(t) {
    var s;
    const e = this.toJson(t);
    return JSON.stringify(e, null, (s = t?.prettySpaces) !== null && s !== void 0 ? s : 0);
  }
  /**
   * Override for serialization behavior. This will be invoked when calling
   * JSON.stringify on this message (i.e. JSON.stringify(msg)).
   *
   * Note that this will not serialize google.protobuf.Any with a packed
   * message because the protobuf JSON format specifies that it needs to be
   * unpacked, and this is only possible with a type registry to look up the
   * message type.  As a result, attempting to serialize a message with this
   * type will throw an Error.
   *
   * This method is protected because you should not need to invoke it
   * directly -- instead use JSON.stringify or toJsonString for
   * stringified JSON.  Alternatively, if actual JSON is desired, you should
   * use toJson.
   */
  toJSON() {
    return this.toJson({
      emitDefaultValues: !0
    });
  }
  /**
   * Retrieve the MessageType of this message - a singleton that represents
   * the protobuf message declaration and provides metadata for reflection-
   * based operations.
   */
  getType() {
    return Object.getPrototypeOf(this).constructor;
  }
}
export {
  h as Message
};
