提交 3df601e8 编写于 作者: 浅梦2013's avatar 浅梦2013

调整 PayloadEncode。

上级 1933ce46
...@@ -22,7 +22,7 @@ import net.dreamlu.iot.mqtt.codec.MqttQoS; ...@@ -22,7 +22,7 @@ import net.dreamlu.iot.mqtt.codec.MqttQoS;
import net.dreamlu.iot.mqtt.core.server.dispatcher.IMqttMessageDispatcher; import net.dreamlu.iot.mqtt.core.server.dispatcher.IMqttMessageDispatcher;
import net.dreamlu.iot.mqtt.core.server.http.api.code.ResultCode; import net.dreamlu.iot.mqtt.core.server.http.api.code.ResultCode;
import net.dreamlu.iot.mqtt.core.server.http.api.form.BaseForm; import net.dreamlu.iot.mqtt.core.server.http.api.form.BaseForm;
import net.dreamlu.iot.mqtt.core.server.http.api.form.PayloadEncode; import net.dreamlu.iot.mqtt.core.util.PayloadEncode;
import net.dreamlu.iot.mqtt.core.server.http.api.form.PublishForm; import net.dreamlu.iot.mqtt.core.server.http.api.form.PublishForm;
import net.dreamlu.iot.mqtt.core.server.http.api.form.SubscribeForm; import net.dreamlu.iot.mqtt.core.server.http.api.form.SubscribeForm;
import net.dreamlu.iot.mqtt.core.server.http.api.result.Result; import net.dreamlu.iot.mqtt.core.server.http.api.result.Result;
......
...@@ -14,9 +14,8 @@ ...@@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package net.dreamlu.iot.mqtt.core.server.http.api.form; package net.dreamlu.iot.mqtt.core.util;
import net.dreamlu.iot.mqtt.core.util.HexUtil;
import org.tio.utils.hutool.StrUtil; import org.tio.utils.hutool.StrUtil;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
...@@ -28,28 +27,51 @@ import java.util.Base64; ...@@ -28,28 +27,51 @@ import java.util.Base64;
* @author L.cm * @author L.cm
*/ */
public enum PayloadEncode { public enum PayloadEncode {
/** /**
* 纯文本、hex、base64 * 纯文本、hex、base64
*/ */
plain { plain {
@Override
public String encode(byte[] data) {
return new String(data, StandardCharsets.UTF_8);
}
@Override @Override
public byte[] decode(String data) { public byte[] decode(String data) {
return data.getBytes(StandardCharsets.UTF_8); return data.getBytes(StandardCharsets.UTF_8);
} }
}, },
hex { hex {
@Override
public String encode(byte[] data) {
return HexUtil.encodeToString(data);
}
@Override @Override
public byte[] decode(String data) { public byte[] decode(String data) {
return HexUtil.decode(data); return HexUtil.decode(data);
} }
}, },
base64 { base64 {
@Override
public String encode(byte[] data) {
return Base64.getEncoder().encodeToString(data);
}
@Override @Override
public byte[] decode(String data) { public byte[] decode(String data) {
return Base64.getDecoder().decode(data); return Base64.getDecoder().decode(data);
} }
}; };
/**
* 编码
*
* @return byte array
*/
public abstract String encode(byte[] data);
/** /**
* 解码 * 解码
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册