package org.eclipse.paho.mqttv5.common.packet;

import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.MqttPersistable;
import org.eclipse.paho.mqttv5.common.MqttPersistenceException;

/* JADX INFO: loaded from: classes2.dex */
public abstract class MqttPersistableWireMessage extends MqttWireMessage implements MqttPersistable {
    @Override // org.eclipse.paho.mqttv5.common.MqttPersistable
    public int getHeaderOffset() throws MqttPersistenceException {
        return 0;
    }

    @Override // org.eclipse.paho.mqttv5.common.MqttPersistable
    public int getPayloadLength() throws MqttPersistenceException {
        return 0;
    }

    @Override // org.eclipse.paho.mqttv5.common.MqttPersistable
    public int getPayloadOffset() throws MqttPersistenceException {
        return 0;
    }

    public MqttPersistableWireMessage(byte b) {
        super(b);
    }

    @Override // org.eclipse.paho.mqttv5.common.MqttPersistable
    public byte[] getHeaderBytes() throws MqttPersistenceException {
        try {
            if (getClass() == MqttPublish.class && getProperties().getTopicAlias() != null) {
                MqttProperties properties = getProperties();
                Integer topicAlias = properties.getTopicAlias();
                properties.setTopicAlias(null);
                byte[] header = getHeader();
                properties.setTopicAlias(topicAlias);
                this.properties = properties;
                return header;
            }
            return getHeader();
        } catch (MqttException e) {
            throw new MqttPersistenceException(e.getCause());
        }
    }

    @Override // org.eclipse.paho.mqttv5.common.MqttPersistable
    public int getHeaderLength() throws MqttPersistenceException {
        return getHeaderBytes().length;
    }

    @Override // org.eclipse.paho.mqttv5.common.MqttPersistable
    public byte[] getPayloadBytes() throws MqttPersistenceException {
        try {
            return getPayload();
        } catch (MqttException e) {
            throw new MqttPersistenceException(e.getCause());
        }
    }
}
