Comments (2)
在边界情况下内置的转义有问题😑,下一个版本修复。
@ryngrok 可以先自己声明一个 BytesEncoder
,覆盖内置逻辑。
@Configuration
public class Jt808Config extends Jt808ServerConfigure {
// io.github.hylexus.jt.config.JtProtocolConstant#BEAN_NAME_JT808_BYTES_ENCODER
@Bean(BEAN_NAME_JT808_BYTES_ENCODER)
public BytesEncoder bytesEncoder() {
return new BytesEncoder.DefaultBytesEncoder() {
@Override
public byte[] doEscapeForReceive(byte[] bs, int start, int end) throws MsgEscapeException {
if (start < 0 || end > bs.length) {
throw new ArrayIndexOutOfBoundsException("doEscape4Receive error : index out of bounds(start=" + start
+ ",end=" + end + ",bytes length=" + bs.length + ")");
}
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
for (int i = 0; i < start; i++) {
outputStream.write(bs[i]);
}
for (int i = start; i < end - 2; i++) {
if (bs[i] == 0x7d && bs[i + 1] == 0x01) {
outputStream.write(0x7d);
i++;
} else if (bs[i] == 0x7d && bs[i + 1] == 0x02) {
outputStream.write(0x7e);
i++;
} else {
outputStream.write(bs[i]);
}
}
if (bs[end - 2] == 0x7d && bs[end - 1] == 0x01) {
outputStream.write(0x7d);
} else if (bs[end - 2] == 0x7d && bs[end - 1] == 0x02) {
outputStream.write(0x7e);
} else {
for (int i = end - 2; i < bs.length; i++) {
outputStream.write(bs[i]);
}
}
return outputStream.toByteArray();
} catch (IOException e) {
throw new MsgEscapeException(e);
}
}
@Override
public byte[] doEscapeForSend(byte[] bs, int start, int end) throws MsgEscapeException {
if (start < 0 || end > bs.length) {
throw new ArrayIndexOutOfBoundsException("doEscape4Send error : index out of bounds(start=" + start
+ ",end=" + end + ",bytes length=" + bs.length + ")");
}
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
for (int i = 0; i < start; i++) {
outputStream.write(bs[i]);
}
for (int i = start; i <= end; i++) {
if (bs[i] == 0x7e) {
outputStream.write(0x7d);
outputStream.write(0x02);
} else {
outputStream.write(bs[i]);
}
}
for (int i = end + 1; i < bs.length; i++) {
outputStream.write(bs[i]);
}
return outputStream.toByteArray();
} catch (IOException e) {
throw new MsgEscapeException(e);
}
}
};
}
}
from jt-framework.
@ryngrok 请升级到 1.0.6-RELEASE
from jt-framework.
Related Issues (20)
- 附加信息。length的类型只能是Integer HOT 1
- DWORD显示应该是有问题的。 HOT 1
- 不支持2019版的消息应答? HOT 1
- handler-scan配置错误
- 麻烦同意一下qq群加入 HOT 1
- 支持808协议的哪些版本? HOT 2
- 报警标志怎么知道具体含义?
- 解析终端参数查询结果 HOT 4
- netty报错 "refCnt: 0, decrement: 1" HOT 1
- 内存泄漏:LEAK: ByteBuf.release() was not called before it's garbage-collected HOT 1
- 服务端无法根据心跳主动断开连接 HOT 1
- 下发终端设置指令异常 HOT 1
- 是否支持JDK 8? HOT 1
- 报文解析错误 HOT 2
- 准备把Gradle升级到7.3.3,报错 HOT 1
- [Question] Logo HOT 1
- 能否安全地去掉注解的 order 属性?
- 在接收不是框架内规定范围内的jt808消息时,会抛异常 HOT 1
- 对于BCD码类型的解析BUG HOT 6
- io.netty.util.ResourceLeakDetector : LEAK: ByteBuf.release() was not called before it's garbage-collected HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jt-framework.