1. 支持String转 GB2312 编码
This commit is contained in:
parent
d29ed06a94
commit
fac5207c5d
|
@ -1,6 +1,7 @@
|
|||
package com.zjyr.beidouservice.adapter.impl.netty.encode;
|
||||
|
||||
import com.zjyr.beidouservice.common.impl.ControlCommandName;
|
||||
import com.zjyr.beidouservice.misc.HelperUtils;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.BaseBinaryProtocol;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.HeartProtocol;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.QuerySensorProtocol;
|
||||
|
@ -14,7 +15,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
|
@ -46,7 +46,8 @@ public class YuanRongProtocolEncode<T> extends MessageToByteEncoder<BaseBinaryPr
|
|||
byte[] ttsArray = new byte[0];
|
||||
|
||||
if (msg.getTtsContent() != null && !msg.getTtsContent().isEmpty()) {
|
||||
ttsArray = msg.getTtsContent().getBytes(StandardCharsets.UTF_16BE);
|
||||
//ttsArray = msg.getTtsContent().getBytes(StandardCharsets.UTF_16BE);
|
||||
ttsArray = HelperUtils.convertStringToGB2312(msg.getTtsContent());
|
||||
ttsSize = ttsArray.length;
|
||||
} else {
|
||||
ttsSize = 0;
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.zjyr.beidouservice.misc;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class HelperUtils {
|
||||
public static String bytesToHexString(byte[] bArray) {
|
||||
StringBuilder sb = new StringBuilder(bArray.length);
|
||||
|
@ -13,6 +16,13 @@ public class HelperUtils {
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static byte[] convertStringToGB2312(String str) throws UnsupportedEncodingException {
|
||||
String utf8 = new String(str.getBytes(StandardCharsets.UTF_8));
|
||||
String unicode = new String(utf8.getBytes(), StandardCharsets.UTF_8);
|
||||
String gbk = new String(unicode.getBytes("GB2312"));
|
||||
return gbk.getBytes();
|
||||
}
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// public static <T> BaseBinaryProtocol<T> CastBaseBinaryProtocol(Object obj) {
|
||||
|
|
Loading…
Reference in New Issue