Skip to content

Commit e383848

Browse files
committed
feat[codec-core]: TLV
1 parent db60451 commit e383848

61 files changed

Lines changed: 2916 additions & 172 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/dictionaries/xtream.xml

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build-script/checkstyle/checkstyle.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
<module name="AbbreviationAsWordInName">
204204
<property name="ignoreFinal" value="false"/>
205205
<property name="allowedAbbreviationLength" value="1"/>
206+
<property name="allowedAbbreviations" value="TLV,URL,UUID,XML,HTTP,AES,DES,RSA"/>
206207
</module>
207208
<module name="OverloadMethodsDeclarationOrder"/>
208209
<module name="VariableDeclarationUsageDistance"/>

debug/jt/jt-808-server-spring-boot-starter-reactive-debug/src/main/java/io/github/hylexus/xtream/debug/ext/jt808/message/DemoLocationMsg03.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public DemoLocationMsg03(Jt808Request request) {
8686
@ValueMatcher(matchU8 = 0x11, valueType = XtreamDataType.byte_array, desc = "长度1或5;超速报警附加信息见 表 28"),
8787
@ValueMatcher(matchU8 = 0x25, valueType = XtreamDataType.u32, desc = "扩展车辆信号状态位,定义见 表 31"),
8888
@ValueMatcher(matchU8 = 0x30, valueType = XtreamDataType.u8, desc = "数据类型为 BYTE,无线通信网络信号强度"),
89-
@ValueMatcher(matchU8 = 0x31, valueType = XtreamDataType.u8, desc = "数据类型为 BYTE,GNSS定位卫星数"),
89+
@ValueMatcher(matchU8 = 0x31, valueType = XtreamDataType.u8, desc = "数据类型为 BYTE,GNSS 定位卫星数"),
9090
@ValueMatcher(matchU8 = 0x64, valueEntity = LocationItem0x64.class, desc = "苏标: 高级驾驶辅助报警信息,定义见表 4-15"),
9191
@ValueMatcher(matchU8 = 0x65, valueEntity = LocationItem0x65.class, desc = "苏标: 驾驶员状态监测系统报警信息,定义见表 4-17"),
9292
@ValueMatcher(matchU8 = 0x66, valueEntity = LocationItem0x66.class, desc = "苏标: 胎压监测系统报警信息,定义见表 4-18"),

ext/jt/jt-808-server-spring-boot-starter-reactive/src/main/java/io/github/hylexus/xtream/codec/ext/jt808/utils/JtCryptoUtil.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ public static byte[] cbcDecrypt(byte[] key, byte[] data, byte[] iv) {
140140

141141
}
142142

143-
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
144143
public static class AES {
145144
static {
146145
addProviderIfNecessary();
@@ -164,7 +163,6 @@ public static byte[] ecbDecrypt(byte[] key, byte[] data) {
164163
}
165164
}
166165

167-
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
168166
public static class DES {
169167
static {
170168
addProviderIfNecessary();
@@ -187,7 +185,6 @@ public static byte[] ecbDecrypt(byte[] key, byte[] data) {
187185
}
188186
}
189187

190-
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
191188
public static class RSA {
192189

193190
static {

ext/jt/jt-808-server-spring-boot-starter-reactive/src/test/java/io/github/hylexus/xtream/codec/ext/jt808/builtin/messages/mixed/MixedEntity02.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonFormat;
2020
import io.github.hylexus.xtream.codec.core.type.Preset;
21-
import io.github.hylexus.xtream.codec.core.type.TLV;
2221
import io.github.hylexus.xtream.codec.core.type.simple.DataField;
2322
import io.github.hylexus.xtream.codec.ext.jt808.extensions.handler.Jt808ResponseBody;
2423
import lombok.Getter;
@@ -69,7 +68,4 @@ public class MixedEntity02 {
6968
@Preset.RustStyle.basic
7069
private DataField.SimpleTlvDataField<DataField.U8> extraItems2;
7170

72-
@Preset.RustStyle.basic
73-
private TLV extraItems3;
74-
7571
}

ext/jt/jt-808-server-spring-boot-starter-reactive/src/test/java/io/github/hylexus/xtream/codec/ext/jt808/builtin/messages/mixed/MixedEntity02Test.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@
1717
package io.github.hylexus.xtream.codec.ext.jt808.builtin.messages.mixed;
1818

1919
import io.github.hylexus.xtream.codec.common.utils.FormatUtils;
20-
import io.github.hylexus.xtream.codec.core.annotation.PaddingType;
2120
import io.github.hylexus.xtream.codec.core.tracker.CodecTracker;
22-
import io.github.hylexus.xtream.codec.core.type.PaddingConfig;
23-
import io.github.hylexus.xtream.codec.core.type.TLV;
24-
import io.github.hylexus.xtream.codec.core.type.FieldLength;
2521
import io.github.hylexus.xtream.codec.core.type.simple.DataField;
26-
import io.github.hylexus.xtream.codec.core.type.wrapper.StringWrapperBcd;
27-
import io.github.hylexus.xtream.codec.core.type.wrapper.U8Wrapper;
2822
import io.github.hylexus.xtream.codec.ext.jt808.builtin.messages.BaseCodecTest;
2923
import io.github.hylexus.xtream.codec.ext.jt808.spec.Jt808MessageDescriber;
3024
import io.github.hylexus.xtream.codec.ext.jt808.spec.Jt808ProtocolVersion;
@@ -67,12 +61,7 @@ void test() {
6761
.setDirection(u16(1))
6862
.setTime(time)
6963
.setExtraItems(extraItems)
70-
.setExtraItems2(tlv(u8((short) 0x01), DataField.ValueLengthType.u8, u32(123L)))
71-
//.setExtraItems3(TLV.of(u8((short) 1), FieldLength.LengthType.u16, new U8Wrapper((short) 3)));
72-
//.setExtraItems3(TLV.of(u8((short) 1), FieldLength.LengthType.u8, new StringWrapperBcd("112233")));
73-
//.setExtraItems3(TLV.of(gbkString("1234",new PaddingConfig(PaddingType.LEFT, (byte) 0x0, 10)), FieldLength.LengthType.u8, new StringWrapperBcd("112233")));
74-
//.setExtraItems3(TLV.of(bcd8421String("1234",new PaddingConfig(PaddingType.LEFT, (byte) 0x0, 10)), FieldLength.LengthType.u8, new StringWrapperBcd("112233")));
75-
.setExtraItems3(TLV.of(u8((short) 1), FieldLength.LengthType.u8, new StringWrapperBcd("112233")));
64+
.setExtraItems2(tlv(u8((short) 0x01), DataField.ValueLengthType.u8, u32(123L)));
7665
dataList.add(mixedEntity02);
7766

7867
final ByteBuf encodeBuffer = responseEncoder.encode(dataList, new Jt808MessageDescriber(0x0200, Jt808ProtocolVersion.VERSION_2013, terminalId2013));

ext/jt/jt-808-server-spring-boot-starter-reactive/src/test/java/io/github/hylexus/xtream/codec/ext/jt808/builtin/messages/mixed/MixedEntity03.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package io.github.hylexus.xtream.codec.ext.jt808.builtin.messages.mixed;
1818

1919
import com.fasterxml.jackson.annotation.JsonFormat;
20-
import io.github.hylexus.xtream.codec.common.bean.BeanPropertyMetadata;
21-
import io.github.hylexus.xtream.codec.core.annotation.XtreamField;
2220
import io.github.hylexus.xtream.codec.core.type.Preset;
2321
import io.github.hylexus.xtream.codec.core.type.TLV;
2422
import io.github.hylexus.xtream.codec.core.type.simple.DataField;
@@ -68,12 +66,8 @@ public class MixedEntity03 {
6866
private LocalDateTime time;
6967

7068
@Preset.RustStyle.list(desc = "扩展项")
71-
@XtreamField(dataType = BeanPropertyMetadata.FiledDataType.sequence)
7269
private List<TLV> extraItems;
7370

74-
@Preset.RustStyle.list(desc = "扩展项")
75-
private TLV extraItems1;
76-
7771
@Preset.RustStyle.basic
7872
private DataField.U8 extraItems2;
7973

ext/jt/jt-808-server-spring-boot-starter-reactive/src/test/java/io/github/hylexus/xtream/codec/ext/jt808/builtin/messages/mixed/MixedEntity03Test.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.github.hylexus.xtream.codec.ext.jt808.builtin.messages.mixed;
1818

19+
import io.github.hylexus.xtream.codec.core.annotation.ext.LengthFieldType;
1920
import io.github.hylexus.xtream.codec.core.type.FieldLength;
2021
import io.github.hylexus.xtream.codec.core.type.TLV;
2122
import io.github.hylexus.xtream.codec.core.type.wrapper.U8Wrapper;
@@ -45,22 +46,21 @@ void test() {
4546
.setTime(time)
4647
.setExtraItems2(u8((short) 0x01))
4748
.setExtraItems3(new U8Wrapper((short) 0x01))
48-
.setExtraItems1(TLV.of(u8((short) 0x01), FieldLength.LengthType.u8, u32(0x01L)))
4949
.setExtraItems(List.of(
50-
TLV.of(u8((short) 0x01), FieldLength.LengthType.u8, u32(11L)),
51-
TLV.of(u8((short) 0x02), FieldLength.LengthType.u8, u16(22)),
52-
TLV.of(u8((short) 0x03), FieldLength.LengthType.u8, u16(33)),
53-
TLV.of(u8((short) 0x04), FieldLength.LengthType.u8, u16(44)),
54-
TLV.of(u8((short) 0x05), FieldLength.LengthType.u8, byteSequence(new byte[]{1, 2, 3, 4, 5})),
55-
TLV.of(u8((short) 0x06), FieldLength.LengthType.u8, i16((short) 66)),
56-
TLV.of(u8((short) 0x11), FieldLength.LengthType.u8, new BuiltinMessage0200.Item0x11((short) 11, 22L)),
57-
TLV.of(u8((short) 0x12), FieldLength.LengthType.u8, new BuiltinMessage0200.Item0x12((short) 11, 22L, (short) 33)),
58-
TLV.of(u8((short) 0x13), FieldLength.LengthType.u8, new BuiltinMessage0200.Item0x13(11L, 22, (short) 33)),
59-
TLV.of(u8((short) 0x25), FieldLength.LengthType.u8, u32(0x25L)),
60-
TLV.of(u8((short) 0x2A), FieldLength.LengthType.u8, u16(0x2A)),
61-
TLV.of(u8((short) 0x2B), FieldLength.LengthType.u8, i32(0x2B)),
62-
TLV.of(u8((short) 0x30), FieldLength.LengthType.u8, u8((short) 30)),
63-
TLV.of(u8((short) 0x31), FieldLength.LengthType.u8, u8((short) 31))
50+
TLV.of(u8((short) 0x01), LengthFieldType.u8, u32(11L)),
51+
TLV.of(u8((short) 0x02), LengthFieldType.u8, u16(22)),
52+
TLV.of(u8((short) 0x03), LengthFieldType.u8, u16(33)),
53+
TLV.of(u8((short) 0x04), LengthFieldType.u8, u16(44)),
54+
TLV.of(u8((short) 0x05), LengthFieldType.u8, byteSequence(new byte[]{1, 2, 3, 4, 5})),
55+
TLV.of(u8((short) 0x06), LengthFieldType.u8, i16((short) 66)),
56+
TLV.of(u8((short) 0x11), LengthFieldType.u8, new BuiltinMessage0200.Item0x11((short) 11, 22L)),
57+
TLV.of(u8((short) 0x12), LengthFieldType.u8, new BuiltinMessage0200.Item0x12((short) 11, 22L, (short) 33)),
58+
TLV.of(u8((short) 0x13), LengthFieldType.u8, new BuiltinMessage0200.Item0x13(11L, 22, (short) 33)),
59+
TLV.of(u8((short) 0x25), LengthFieldType.u8, u32(0x25L)),
60+
TLV.of(u8((short) 0x2A), LengthFieldType.u8, u16(0x2A)),
61+
TLV.of(u8((short) 0x2B), LengthFieldType.u8, i32(0x2B)),
62+
TLV.of(u8((short) 0x30), LengthFieldType.u8, u8((short) 30)),
63+
TLV.of(u8((short) 0x31), LengthFieldType.u8, u8((short) 31))
6464
));
6565
final String hex = this.encode(sourceEntity, Jt808ProtocolVersion.VERSION_2013, terminalId2013);
6666
System.out.println(hex);

xtream-codec-core/src/main/java/io/github/hylexus/xtream/codec/common/bean/BeanPropertyMetadata.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ default boolean isRecordComponent() {
9292

9393
FieldLengthExtractor fieldLengthExtractor();
9494

95-
default IterationTimesExtractor iterationTimesExtractor() {
96-
throw new UnsupportedOperationException();
97-
}
95+
IterationTimesExtractor iterationTimesExtractor();
9896

9997
FieldConditionEvaluator conditionEvaluator();
10098

xtream-codec-core/src/main/java/io/github/hylexus/xtream/codec/common/bean/IterationTimesExtractor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,22 @@
2222
import org.springframework.expression.EvaluationContext;
2323
import org.springframework.expression.Expression;
2424
import org.springframework.expression.spel.standard.SpelExpressionParser;
25+
import org.springframework.util.StringUtils;
2526

2627
public interface IterationTimesExtractor {
2728

2829
int extractIterationTimes(FieldCodec.DeserializeContext context, EvaluationContext evaluationContext);
2930

31+
static IterationTimesExtractor from(XtreamField xtreamField) {
32+
if (xtreamField.iterationTimes() > 0) {
33+
return new IterationTimesExtractor.ConstantIterationTimesExtractor(xtreamField.iterationTimes());
34+
}
35+
if (StringUtils.hasText(xtreamField.iterationTimesExpression())) {
36+
return new IterationTimesExtractor.ExpressionIterationTimesExtractor(xtreamField);
37+
}
38+
return IterationTimesExtractor.PlaceholderIterationTimesExtractor.DEFAULT;
39+
}
40+
3041
@ToString
3142
class ConstantIterationTimesExtractor implements IterationTimesExtractor {
3243
private final int length;

0 commit comments

Comments
 (0)