, ParserDataType> typeMap = new HashMap<>(length << 1);
+ for(int i = 0; i < length; i ++){
final ParserDataType dt = values[i];
+
primitiveWrapperMap.put(dt.primitiveType, dt.objectiveType);
wrapperPrimitiveMap.put(dt.objectiveType, dt.primitiveType);
typeMap.put(dt.primitiveType, dt);
@@ -263,8 +267,8 @@ static String describe(){
* @throws CodecException If the value cannot be interpreted as primitive or objective.
*/
public static Object getValueOrSelf(final Class> fieldType, final Object value) throws CodecException{
- return (value instanceof String
- ? getValue(fieldType, (String)value)
+ return (value instanceof String v
+ ? getValue(fieldType, v)
: value);
}
@@ -276,7 +280,6 @@ public static Object getValueOrSelf(final Class> fieldType, final Object value
* @return The primitive or objective value.
* @throws CodecException If the value cannot be interpreted as primitive or objective.
*/
- @SuppressWarnings("ReturnOfNull")
public static Object getValue(final Class> fieldType, final String value) throws CodecException{
if(fieldType == String.class)
return value;
@@ -292,24 +295,58 @@ public static Object getValue(final Class> fieldType, final String value) thro
: val);
}
-
private static Object toNumber(final String text, final Class> objectiveType){
- Object response = null;
+ Object result = null;
if(isNumeric(text)){
try{
- final Method method = objectiveType.getDeclaredMethod(METHOD_VALUE_OF, String.class, int.class);
- final boolean hexadecimal = text.startsWith("0x");
- response = method.invoke(null, (hexadecimal? text.substring(2): text), (hexadecimal? 16: 10));
+ final BigInteger decValue = (text.startsWith("0x")
+ ? new BigInteger(text.substring(2), 16)
+ : new BigInteger(text));
+ final int maxBytes = (int)objectiveType.getDeclaredField("BYTES")
+ .get(null);
+ if(decValue.bitCount() <= maxBytes << 3){
+ //extract decimal value as object
+ final byte[] byteArray = decValue.toByteArray();
+ if(maxBytes == Byte.BYTES)
+ result = byteArray[0];
+ else{
+ long value = 0l;
+ for(int i = 0, length = byteArray.length; i < length; i ++)
+ value |= (byteArray[i] & 0xFFl) << (Byte.SIZE * (length - 1 - i));
+
+ if(maxBytes == Short.BYTES)
+ result = (short)value;
+ else if(maxBytes == Integer.BYTES)
+ result = (int)value;
+ else if(maxBytes == Long.BYTES)
+ result = value;
+ }
+ }
}
- catch(final NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored){}
+ catch(final NoSuchFieldException | IllegalAccessException ignored){}
}
- return response;
+ return result;
}
private static boolean isNumeric(final String text){
return (isHexadecimalNumber(text) || isDecimalNumber(text));
}
+ /**
+ * Returns the primitive or objective type (depending on the field type) data stored as a string value.
+ *
+ * @param value The string value to be interpreted.
+ * @return The primitive or objective value as an unsigned number (e.g. `(byte)0xFF` is 255 rather than -1).
+ */
+ public static Number getBigNumber(final String value){
+ if(value == null || value.isEmpty())
+ return null;
+
+ return (value.startsWith("0x")
+ ? new BigInteger(value.substring(2), 16)
+ : new BigDecimal(value));
+ }
+
/**
* Checks if the text contains only Unicode digits.
@@ -349,8 +386,9 @@ private static boolean isHexadecimalNumber(final String text){
}
private static boolean isBaseNumber(final CharSequence text, final int offset, final int radix){
- for(int i = offset; i < text.length(); i ++){
+ for(int i = offset, length = text.length(); i < length; i ++){
final char chr = text.charAt(i);
+
if(Character.digit(chr, radix) < 0)
return true;
}
diff --git a/src/main/java/io/github/mtrevisan/boxon/logs/EventListener.java b/src/main/java/io/github/mtrevisan/boxon/logs/EventListener.java
index f941d63a3..e69c70862 100644
--- a/src/main/java/io/github/mtrevisan/boxon/logs/EventListener.java
+++ b/src/main/java/io/github/mtrevisan/boxon/logs/EventListener.java
@@ -33,7 +33,7 @@
*/
public class EventListener{
- private static class SingletonHelper{
+ private static final class SingletonHelper{
private static final EventListener INSTANCE = new EventListener();
}
diff --git a/src/main/java/io/github/mtrevisan/boxon/logs/EventLogger.java b/src/main/java/io/github/mtrevisan/boxon/logs/EventLogger.java
index e2bc50e96..3c1ed5836 100644
--- a/src/main/java/io/github/mtrevisan/boxon/logs/EventLogger.java
+++ b/src/main/java/io/github/mtrevisan/boxon/logs/EventLogger.java
@@ -51,7 +51,7 @@ public final class EventLogger extends EventListener{
private static final Logger LOGGER = LoggerFactory.getLogger(EventLogger.class);
- private static class SingletonHelper{
+ private static final class SingletonHelper{
private static final EventLogger INSTANCE = new EventLogger();
}
@@ -79,7 +79,7 @@ public void loadingCodecsFrom(final Class>[] basePackageClasses){
public void loadingCodec(final Class>[] codecClasses){
if(LOGGER.isInfoEnabled()){
final StringJoiner sj = new StringJoiner(", ", "[", "]");
- for(int i = 0; i < codecClasses.length; i ++)
+ for(int i = 0, length = codecClasses.length; i < length; i ++)
sj.add(codecClasses[i].getSimpleName());
info("Loading codecs: {}", sj.toString());
@@ -105,7 +105,7 @@ public void loadingTemplatesFrom(final Class>[] basePackageClasses){
private static StringJoiner joinPackageNames(final Class>[] basePackageClasses){
final StringJoiner sj = new StringJoiner(", ", "[", "]");
- for(int i = 0; i < basePackageClasses.length; i ++)
+ for(int i = 0, length = basePackageClasses.length; i < length; i ++)
sj.add(basePackageClasses[i].getPackageName());
return sj;
}
@@ -225,8 +225,9 @@ private static Object[] extractParameters(final Object[] parameters){
}
private static Collection collectPackages(final Object[] parameters){
- final Collection packages = new HashSet<>(parameters.length);
- for(int i = 0; i < parameters.length; i ++)
+ final int length = parameters.length;
+ final Collection packages = new HashSet<>(length);
+ for(int i = 0; i < length; i ++)
packages.add(((Class>)parameters[i]).getPackageName());
return packages;
}
diff --git a/src/main/java/io/github/mtrevisan/boxon/semanticversioning/Version.java b/src/main/java/io/github/mtrevisan/boxon/semanticversioning/Version.java
index b92be844a..9526ef997 100644
--- a/src/main/java/io/github/mtrevisan/boxon/semanticversioning/Version.java
+++ b/src/main/java/io/github/mtrevisan/boxon/semanticversioning/Version.java
@@ -221,8 +221,6 @@ private static Integer parseIdentifier(final String[] tokens, final int index, f
}
private static void validateToken(final String type, final String token) throws VersionException{
- if(hasLeadingZeros(token))
- throw VersionException.create("The {} identifier MUST NOT contain leading zeros", type);
try{
final int number = Integer.parseInt(token);
if(number < 0)
@@ -234,7 +232,7 @@ private static void validateToken(final String type, final String token) throws
}
private static void validatePreRelease(final String[] preRelease) throws VersionException{
- for(int i = 0; i < preRelease.length; i ++)
+ for(int i = 0, length = preRelease.length; i < length; i ++)
validatePreRelease(preRelease[i]);
}
@@ -247,7 +245,7 @@ private static void validatePreRelease(final String pr){
}
private static void validateBuild(final String[] build) throws VersionException{
- for(int i = 0; i < build.length; i ++)
+ for(int i = 0, length = build.length; i < length; i ++)
validateBuild(build[i]);
}
@@ -404,7 +402,7 @@ private static int compareToIdentifiers(final String[] preRelease, final String[
private static int compareIdentifierArrays(final String[] preRelease, final String[] otherPreRelease){
int result = (otherPreRelease.length - preRelease.length);
- for(int i = 0; i < getLeastCommonArrayLength(preRelease, otherPreRelease); i ++){
+ for(int i = 0, length = getLeastCommonArrayLength(preRelease, otherPreRelease); i < length; i ++){
result = compareIdentifiers(preRelease[i], otherPreRelease[i]);
if(result != 0)
break;
@@ -440,8 +438,9 @@ private static int compareIdentifiers(final String identifier1, final String ide
*/
private static boolean containsOnlyValidChars(String text){
text = text.toUpperCase(Locale.ROOT);
- for(int i = 0; i < text.length(); i ++){
+ for(int i = 0, length = text.length(); i < length; i ++){
final char chr = text.charAt(i);
+
if(chr != '-' && (chr < 'A' || chr > 'Z'))
return false;
}
@@ -628,14 +627,11 @@ public Version setBuild(final String... build) throws VersionException{
}
- private static boolean hasLeadingZeros(final CharSequence token){
- return (token.length() > 1 && token.charAt(0) == '0');
- }
-
private static int getLeastCommonArrayLength(final String[] array1, final String[] array2){
return Math.min(array1.length, array2.length);
}
+
@Override
public String toString(){
String message = JavaHelper.EMPTY_STRING;
diff --git a/src/main/java/io/github/mtrevisan/boxon/semanticversioning/VersionException.java b/src/main/java/io/github/mtrevisan/boxon/semanticversioning/VersionException.java
index 79272f01f..31fb13c39 100644
--- a/src/main/java/io/github/mtrevisan/boxon/semanticversioning/VersionException.java
+++ b/src/main/java/io/github/mtrevisan/boxon/semanticversioning/VersionException.java
@@ -26,12 +26,15 @@
import io.github.mtrevisan.boxon.helpers.StringHelper;
+import java.io.Serial;
+
/**
* Represents an error in a version.
*/
public final class VersionException extends IllegalArgumentException{
+ @Serial
private static final long serialVersionUID = 6010765672515345324L;
diff --git a/src/test/java/io/github/mtrevisan/boxon/core/ComposerTest.java b/src/test/java/io/github/mtrevisan/boxon/core/ComposerTest.java
index a231caacd..ee722b780 100644
--- a/src/test/java/io/github/mtrevisan/boxon/core/ComposerTest.java
+++ b/src/test/java/io/github/mtrevisan/boxon/core/ComposerTest.java
@@ -46,7 +46,7 @@ class ComposerTest{
@Test
void parseAndComposeSingleMessageHex() throws NoSuchMethodException, AnnotationException, TemplateException, ConfigurationException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withContextPair("deviceTypes", deviceTypes)
.withContextFunction(ParserTest.class, "headerLength")
@@ -76,7 +76,7 @@ void parseAndComposeSingleMessageHex() throws NoSuchMethodException, AnnotationE
@Test
void parseAndComposeSingleMessageASCII() throws AnnotationException, TemplateException, ConfigurationException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GV350M", (byte)0xCF);
+ .with((byte)0xCF, "QUECLINK_GV350M");
Map context = Collections.singletonMap("deviceTypes", deviceTypes);
Core core = CoreBuilder.builder()
.withContext(context)
diff --git a/src/test/java/io/github/mtrevisan/boxon/core/ComposerThreadedTest.java b/src/test/java/io/github/mtrevisan/boxon/core/ComposerThreadedTest.java
index fe822164d..897c71dd5 100644
--- a/src/test/java/io/github/mtrevisan/boxon/core/ComposerThreadedTest.java
+++ b/src/test/java/io/github/mtrevisan/boxon/core/ComposerThreadedTest.java
@@ -48,7 +48,7 @@ class ComposerThreadedTest{
void concurrencySingleParserSingleCore() throws NoSuchMethodException, AnnotationException, TemplateException, ConfigurationException,
ExecutionException, InterruptedException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withContextPair("deviceTypes", deviceTypes)
.withContextFunction(ParserTest.class, "headerLength")
@@ -74,7 +74,7 @@ void concurrencySingleParserSingleCore() throws NoSuchMethodException, Annotatio
void concurrencyMultipleParserSingleCore() throws NoSuchMethodException, AnnotationException, TemplateException, ConfigurationException,
ExecutionException, InterruptedException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withContextPair("deviceTypes", deviceTypes)
.withContextFunction(ParserTest.class, "headerLength")
@@ -102,7 +102,7 @@ void concurrencyMultipleParserSingleCore() throws NoSuchMethodException, Annotat
void concurrencyMultipleParserMultipleCore() throws NoSuchMethodException, AnnotationException, TemplateException,
ConfigurationException, ExecutionException, InterruptedException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
//compose:
int threadCount = 10;
diff --git a/src/test/java/io/github/mtrevisan/boxon/core/ConfiguratorTest.java b/src/test/java/io/github/mtrevisan/boxon/core/ConfiguratorTest.java
index c9b7dc409..89157af52 100644
--- a/src/test/java/io/github/mtrevisan/boxon/core/ConfiguratorTest.java
+++ b/src/test/java/io/github/mtrevisan/boxon/core/ConfiguratorTest.java
@@ -45,7 +45,7 @@ class ConfiguratorTest{
@Test
void getConfigurations() throws AnnotationException, ConfigurationException, CodecException, TemplateException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withDefaultCodecs()
.withConfiguration(REGConfigurationASCII.class)
@@ -63,14 +63,14 @@ void getConfigurations() throws AnnotationException, ConfigurationException, Cod
ConfigurationKey.CONFIGURATION_PROTOCOL_VERSION_BOUNDARIES.toString()));
Assertions.assertEquals("{longDescription:The command AT+GTREG is used to do things.,maxProtocol:2.8,shortDescription:AT+GTREG}", jsonHeader);
- Assertions.assertEquals("{Operation mode report interval:{minValue:3600,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.21,fieldType:int},Maximum download retry count:{alternatives:[{maxProtocol:1.20,minValue:0,fieldType:int,maxValue:3,defaultValue:0},{minValue:0,fieldType:int,maxValue:3,minProtocol:1.21,defaultValue:1}]},Download timeout:{alternatives:[{maxProtocol:1.18,minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:10},{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,minProtocol:1.19,defaultValue:20}]},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{alternatives:[{maxProtocol:1.35,enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},{enumeration:[HTTP, HTTPS],minProtocol:1.36,defaultValue:HTTP,mutuallyExclusive:true}]},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:int},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int}}", jsonFields);
+ Assertions.assertEquals("{Operation mode report interval:{minValue:3600,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.21,fieldType:int},Maximum download retry count:{alternatives:[{maxProtocol:1.20,minValue:0,fieldType:int,maxValue:3,defaultValue:0},{minValue:0,fieldType:int,maxValue:3,minProtocol:1.21,defaultValue:1}]},Download timeout:{alternatives:[{maxProtocol:1.18,minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:10},{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,minProtocol:1.19,defaultValue:20}]},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{alternatives:[{maxProtocol:1.35,enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},{enumeration:[HTTP, HTTPS],minProtocol:1.36,defaultValue:HTTPS,mutuallyExclusive:true}]},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:short},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int}}", jsonFields);
Assertions.assertEquals("[1.18,1.19,1.20,1.21,1.35,1.36,2.8]", jsonProtocolVersionBoundaries);
}
@Test
void getProtocolVersionBoundaries() throws AnnotationException, ConfigurationException, TemplateException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withDefaultCodecs()
.withConfigurationsFrom(REGConfigurationASCII.class)
@@ -87,7 +87,7 @@ void getProtocolVersionBoundaries() throws AnnotationException, ConfigurationExc
@Test
void getConfigurationsByProtocol() throws AnnotationException, ConfigurationException, CodecException, TemplateException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withDefaultCodecs()
.withConfigurationsFrom(REGConfigurationASCII.class)
@@ -103,13 +103,13 @@ void getConfigurationsByProtocol() throws AnnotationException, ConfigurationExce
String jsonFields = PrettyPrintMap.toString(configuration.get(ConfigurationKey.CONFIGURATION_FIELDS.toString()));
Assertions.assertEquals("{longDescription:The command AT+GTREG is used to do things.,shortDescription:AT+GTREG}", jsonHeader);
- Assertions.assertEquals("{Maximum download retry count:{minValue:0,fieldType:int,maxValue:3,defaultValue:0},Download timeout:{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:20},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:int},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,fieldType:int}}", jsonFields);
+ Assertions.assertEquals("{Maximum download retry count:{minValue:0,fieldType:int,maxValue:3,defaultValue:0},Download timeout:{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:20},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:short},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,fieldType:int}}", jsonFields);
}
@Test
void composeSingleConfigurationMessage() throws NoSuchMethodException, AnnotationException, TemplateException, ConfigurationException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withDefaultCodecs()
.withConfigurationsFrom(REGConfigurationASCII.class)
@@ -129,7 +129,7 @@ void composeSingleConfigurationMessage() throws NoSuchMethodException, Annotatio
));
configurationData.put("Update mode", 0);
configurationData.put("Maximum download retry count", 2);
- configurationData.put("Message counter", 123);
+ configurationData.put("Message counter", (short)123);
configurationData.put("Operation mode", 1);
configurationData.put("Password", "pass");
configurationData.put("Download timeout", 25);
@@ -139,7 +139,7 @@ void composeSingleConfigurationMessage() throws NoSuchMethodException, Annotatio
configurationData);
Assertions.assertFalse(composeResult.hasError());
- Assertions.assertEquals("AT+GTREG=pass,1,1,0,2,25,0,http://url.com@username@password,3600,3600,6,,7b$",
+ Assertions.assertEquals("AT+GTREG=pass,1,1,0,2,25,0,http://url.com@username@password,3600,3600,06,,7B$",
new String(composeResult.getMessage()));
}
diff --git a/src/test/java/io/github/mtrevisan/boxon/core/ConfiguratorThreadedTest.java b/src/test/java/io/github/mtrevisan/boxon/core/ConfiguratorThreadedTest.java
index dd89bbaf6..7a48a371f 100644
--- a/src/test/java/io/github/mtrevisan/boxon/core/ConfiguratorThreadedTest.java
+++ b/src/test/java/io/github/mtrevisan/boxon/core/ConfiguratorThreadedTest.java
@@ -46,7 +46,7 @@ class ConfiguratorThreadedTest{
void concurrencySingleParserSingleCore() throws AnnotationException, ConfigurationException, CodecException, TemplateException,
ExecutionException, InterruptedException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withDefaultCodecs()
.withConfiguration(REGConfigurationASCII.class)
@@ -63,7 +63,7 @@ void concurrencySingleParserSingleCore() throws AnnotationException, Configurati
ConfigurationKey.CONFIGURATION_PROTOCOL_VERSION_BOUNDARIES.toString()));
Assertions.assertEquals("{longDescription:The command AT+GTREG is used to do things.,maxProtocol:2.8,shortDescription:AT+GTREG}", jsonHeader);
- Assertions.assertEquals("{Operation mode report interval:{minValue:3600,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.21,fieldType:int},Maximum download retry count:{alternatives:[{maxProtocol:1.20,minValue:0,fieldType:int,maxValue:3,defaultValue:0},{minValue:0,fieldType:int,maxValue:3,minProtocol:1.21,defaultValue:1}]},Download timeout:{alternatives:[{maxProtocol:1.18,minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:10},{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,minProtocol:1.19,defaultValue:20}]},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{alternatives:[{maxProtocol:1.35,enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},{enumeration:[HTTP, HTTPS],minProtocol:1.36,defaultValue:HTTP,mutuallyExclusive:true}]},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:int},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int}}", jsonFields);
+ Assertions.assertEquals("{Operation mode report interval:{minValue:3600,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.21,fieldType:int},Maximum download retry count:{alternatives:[{maxProtocol:1.20,minValue:0,fieldType:int,maxValue:3,defaultValue:0},{minValue:0,fieldType:int,maxValue:3,minProtocol:1.21,defaultValue:1}]},Download timeout:{alternatives:[{maxProtocol:1.18,minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:10},{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,minProtocol:1.19,defaultValue:20}]},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{alternatives:[{maxProtocol:1.35,enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},{enumeration:[HTTP, HTTPS],minProtocol:1.36,defaultValue:HTTPS,mutuallyExclusive:true}]},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:short},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int}}", jsonFields);
Assertions.assertEquals("[1.18,1.19,1.20,1.21,1.35,1.36,2.8]", jsonProtocolVersionBoundaries);
},
10
@@ -74,7 +74,7 @@ void concurrencySingleParserSingleCore() throws AnnotationException, Configurati
void concurrencyMultipleParserSingleCore() throws AnnotationException, ConfigurationException, CodecException, TemplateException,
ExecutionException, InterruptedException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withDefaultCodecs()
.withConfiguration(REGConfigurationASCII.class)
@@ -93,7 +93,7 @@ void concurrencyMultipleParserSingleCore() throws AnnotationException, Configura
ConfigurationKey.CONFIGURATION_PROTOCOL_VERSION_BOUNDARIES.toString()));
Assertions.assertEquals("{longDescription:The command AT+GTREG is used to do things.,maxProtocol:2.8,shortDescription:AT+GTREG}", jsonHeader);
- Assertions.assertEquals("{Operation mode report interval:{minValue:3600,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.21,fieldType:int},Maximum download retry count:{alternatives:[{maxProtocol:1.20,minValue:0,fieldType:int,maxValue:3,defaultValue:0},{minValue:0,fieldType:int,maxValue:3,minProtocol:1.21,defaultValue:1}]},Download timeout:{alternatives:[{maxProtocol:1.18,minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:10},{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,minProtocol:1.19,defaultValue:20}]},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{alternatives:[{maxProtocol:1.35,enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},{enumeration:[HTTP, HTTPS],minProtocol:1.36,defaultValue:HTTP,mutuallyExclusive:true}]},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:int},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int}}", jsonFields);
+ Assertions.assertEquals("{Operation mode report interval:{minValue:3600,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.21,fieldType:int},Maximum download retry count:{alternatives:[{maxProtocol:1.20,minValue:0,fieldType:int,maxValue:3,defaultValue:0},{minValue:0,fieldType:int,maxValue:3,minProtocol:1.21,defaultValue:1}]},Download timeout:{alternatives:[{maxProtocol:1.18,minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:10},{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,minProtocol:1.19,defaultValue:20}]},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{alternatives:[{maxProtocol:1.35,enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},{enumeration:[HTTP, HTTPS],minProtocol:1.36,defaultValue:HTTPS,mutuallyExclusive:true}]},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:short},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int}}", jsonFields);
Assertions.assertEquals("[1.18,1.19,1.20,1.21,1.35,1.36,2.8]", jsonProtocolVersionBoundaries);
},
10
@@ -104,7 +104,7 @@ void concurrencyMultipleParserSingleCore() throws AnnotationException, Configura
void concurrencyMultipleParserMultipleCore() throws AnnotationException, ConfigurationException, CodecException, TemplateException,
ExecutionException, InterruptedException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
MultithreadingHelper.testMultithreading(
() -> {
@@ -123,7 +123,7 @@ void concurrencyMultipleParserMultipleCore() throws AnnotationException, Configu
ConfigurationKey.CONFIGURATION_PROTOCOL_VERSION_BOUNDARIES.toString()));
Assertions.assertEquals("{longDescription:The command AT+GTREG is used to do things.,maxProtocol:2.8,shortDescription:AT+GTREG}", jsonHeader);
- Assertions.assertEquals("{Operation mode report interval:{minValue:3600,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.21,fieldType:int},Maximum download retry count:{alternatives:[{maxProtocol:1.20,minValue:0,fieldType:int,maxValue:3,defaultValue:0},{minValue:0,fieldType:int,maxValue:3,minProtocol:1.21,defaultValue:1}]},Download timeout:{alternatives:[{maxProtocol:1.18,minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:10},{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,minProtocol:1.19,defaultValue:20}]},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{alternatives:[{maxProtocol:1.35,enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},{enumeration:[HTTP, HTTPS],minProtocol:1.36,defaultValue:HTTP,mutuallyExclusive:true}]},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:int},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int}}", jsonFields);
+ Assertions.assertEquals("{Operation mode report interval:{minValue:3600,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.21,fieldType:int},Maximum download retry count:{alternatives:[{maxProtocol:1.20,minValue:0,fieldType:int,maxValue:3,defaultValue:0},{minValue:0,fieldType:int,maxValue:3,minProtocol:1.21,defaultValue:1}]},Download timeout:{alternatives:[{maxProtocol:1.18,minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,defaultValue:10},{minValue:5,unitOfMeasure:min,fieldType:int,maxValue:30,minProtocol:1.19,defaultValue:20}]},Weekday:{defaultValue:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY],enumeration:[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]},Update Over-The-Air:{defaultValue:FALSE,mutuallyExclusive:true,enumeration:[TRUE, FALSE]},Header:{charset:UTF-8,defaultValue:GTREG,fieldType:String},Download protocol:{alternatives:[{maxProtocol:1.35,enumeration:[HTTP, HTTPS],defaultValue:HTTP,mutuallyExclusive:true},{enumeration:[HTTP, HTTPS],minProtocol:1.36,defaultValue:HTTPS,mutuallyExclusive:true}]},Download URL:{pattern:.{0,100},charset:UTF-8,fields:{URL:{pattern:https?://.{0,92},fieldType:String},password:{pattern:.{1,32},fieldType:String},username:{pattern:.{1,32},fieldType:String}}},Update mode:{minValue:0,maxValue:1,defaultValue:1,fieldType:int},Message counter:{minValue:0,maxValue:65535,fieldType:short},Operation mode:{minValue:0,maxValue:3,defaultValue:0,fieldType:int},Motion report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int},Password:{charset:UTF-8,defaultValue:gb200s,pattern:[0-9a-zA-Z]{4,20},fieldType:String},Motionless report interval:{maxProtocol:1.20,minValue:90,unitOfMeasure:s,maxValue:86400,defaultValue:3600,minProtocol:1.19,fieldType:int}}", jsonFields);
Assertions.assertEquals("[1.18,1.19,1.20,1.21,1.35,1.36,2.8]", jsonProtocolVersionBoundaries);
},
10
diff --git a/src/test/java/io/github/mtrevisan/boxon/core/DescriptorTest.java b/src/test/java/io/github/mtrevisan/boxon/core/DescriptorTest.java
index 02c862e09..1e3a7d959 100644
--- a/src/test/java/io/github/mtrevisan/boxon/core/DescriptorTest.java
+++ b/src/test/java/io/github/mtrevisan/boxon/core/DescriptorTest.java
@@ -49,7 +49,7 @@ class DescriptorTest{
@Test
void description() throws AnnotationException, ConfigurationException, CodecException, TemplateException, NoSuchMethodException{
DeviceTypes deviceTypes = DeviceTypes.create()
- .with("QUECLINK_GB200S", (byte)0x46);
+ .with((byte)0x46, "QUECLINK_GB200S");
Core core = CoreBuilder.builder()
.withContextPair("deviceTypes", deviceTypes)
.withContextFunction(ParserTest.class.getDeclaredMethod("headerLength"))
@@ -58,14 +58,17 @@ void description() throws AnnotationException, ConfigurationException, CodecExce
.create();
Descriptor descriptor = Descriptor.create(core);
- List