package ed;

import androidx.annotation.Nullable;
import java.nio.ByteBuffer;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

/* JADX INFO: loaded from: classes.dex */
public final class m implements p {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final m f25840a = new m();

    @Override // ed.p
    @Nullable
    public Object decodeMessage(@Nullable ByteBuffer byteBuffer) {
        if (byteBuffer == null) {
            return null;
        }
        try {
            JSONTokener jSONTokener = new JSONTokener(b0.f25831b.decodeMessage(byteBuffer));
            Object objNextValue = jSONTokener.nextValue();
            if (jSONTokener.more()) {
                throw new IllegalArgumentException("Invalid JSON");
            }
            return objNextValue;
        } catch (JSONException e10) {
            throw new IllegalArgumentException("Invalid JSON", e10);
        }
    }

    @Override // ed.p
    @Nullable
    public ByteBuffer encodeMessage(@Nullable Object obj) {
        if (obj == null) {
            return null;
        }
        Object objWrap = o.wrap(obj);
        return objWrap instanceof String ? b0.f25831b.encodeMessage(JSONObject.quote((String) objWrap)) : b0.f25831b.encodeMessage(objWrap.toString());
    }
}
