package org.eclipse.paho.mqttv5.common;

import org.eclipse.paho.mqttv5.common.packet.MqttProperties;

/* JADX INFO: loaded from: classes2.dex */
public class MqttMessage {
    private int messageId;
    private byte[] payload;
    private MqttProperties properties;
    private boolean mutable = true;
    private int qos = 1;
    private boolean retained = false;
    private boolean dup = false;

    public static void validateQos(int i) {
        if (i < 0 || i > 2) {
            throw new IllegalArgumentException();
        }
    }

    public MqttMessage() {
        setPayload(new byte[0]);
    }

    public MqttMessage(byte[] bArr) {
        setPayload(bArr);
    }

    public MqttMessage(byte[] bArr, int i, boolean z, MqttProperties mqttProperties) {
        setPayload(bArr);
        setQos(i);
        setRetained(z);
        setProperties(mqttProperties);
    }

    public byte[] getPayload() {
        return this.payload;
    }

    public void clearPayload() {
        checkMutable();
        this.payload = new byte[0];
    }

    public void setPayload(byte[] bArr) {
        checkMutable();
        bArr.getClass();
        this.payload = bArr;
    }

    public boolean isRetained() {
        return this.retained;
    }

    public void setRetained(boolean z) {
        checkMutable();
        this.retained = z;
    }

    public int getQos() {
        return this.qos;
    }

    public void setQos(int i) {
        checkMutable();
        validateQos(i);
        this.qos = i;
    }

    public void setMutable(boolean z) {
        this.mutable = z;
    }

    protected void checkMutable() throws IllegalStateException {
        if (!this.mutable) {
            throw new IllegalStateException();
        }
    }

    public void setDuplicate(boolean z) {
        this.dup = z;
    }

    public boolean isDuplicate() {
        return this.dup;
    }

    public void setId(int i) {
        this.messageId = i;
    }

    public int getId() {
        return this.messageId;
    }

    public MqttProperties getProperties() {
        return this.properties;
    }

    public void setProperties(MqttProperties mqttProperties) {
        this.properties = mqttProperties;
    }

    public String toString() {
        return new String(this.payload);
    }

    public String toDebugString() {
        return "MqttMessage [mutable=" + this.mutable + ", payload=" + new String(this.payload) + ", qos=" + this.qos + ", retained=" + this.retained + ", dup=" + this.dup + ", messageId=" + this.messageId + "]";
    }
}
