fix several critial bug

details
 - code refine
 "In Kotlin 1.3, it is now possible to capture the when subject into variable"
 - fix gradle version checking bug: now we can handle versions like "5.4-rc-1" and "5.4"
 - removed unwanted import of "UnImplNode"
 - add Struct3 doc
pull/31/head
cfig 6 years ago
parent 3dd9f1e685
commit 32139203e7
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -2,7 +2,6 @@ package cfig
import cfig.io.Struct3
import com.google.common.math.BigIntegerMath
import com.sun.org.apache.xml.internal.utils.UnImplNode
import org.apache.commons.codec.binary.Hex
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream
import org.apache.commons.compress.compressors.gzip.GzipParameters

@ -108,7 +108,7 @@ class Struct3 {
fun calcSize(): Int? {
var ret = 0
for (format in formats) {
when (format[0]) {
when (val formatType = format[0]) {
Byte, UByte, Char, String, Type.Padding -> {
ret += format[1] as Int
}
@ -122,7 +122,7 @@ class Struct3 {
ret += 8 * format[1] as Int
}
else -> {
throw IllegalArgumentException("Class [" + format[0] + "] not supported")
throw IllegalArgumentException("Class [" + formatType + "] not supported")
}
}
}

@ -9,8 +9,9 @@ subprojects {
// ----------------------------------------------------------------------------
// global
// ----------------------------------------------------------------------------
if (Float.parseFloat(gradle.gradleVersion) < 5.0) {
import java.util.regex.Matcher
import java.util.regex.Pattern
if (parseGradleVersion(gradle.gradleVersion) < 5) {
logger.error("ERROR: Gradle Version MUST >= 5.0, current is {}", gradle.gradleVersion)
throw new RuntimeException("ERROR: Gradle Version")
} else {
@ -174,3 +175,15 @@ task rr {
rebootRecovery()
}
}
int parseGradleVersion(String version) {
Pattern VERSION_PATTERN = Pattern.compile("((\\d+)(\\.\\d+)+)(-(\\p{Alpha}+)-(\\w+))?(-(SNAPSHOT|\\d{14}([-+]\\d{4})?))?")
Matcher matcher = VERSION_PATTERN.matcher(version)
if (!matcher.matches()) {
throw new IllegalArgumentException(format("'%s' is not a valid Gradle version string (examples: '1.0', '1.0-rc-1')", version))
}
String versionPart = matcher.group(1)
int majorPart = Integer.parseInt(matcher.group(2), 10)
logger.info("Gradle: versionPart {}, majorPart {}", versionPart, majorPart)
return majorPart
}

@ -0,0 +1,21 @@
'Struct3' formats
| Format | C Type | Python type | Standard size | Type | Parameter | Size |
| -- | -- | -- | -- | -- | -- | -- |
| x | pad byte | no value | | Type.Padding | "null,Byte,Int (only lower 8 bits are kept)" | 1 |
| c | char | bytes of length 1 | 1 | kotlin.Char | "Character.class (only lower 8 bits are kept, higher 8 bits are discarded)" | 1 |
| b | signed char | integer | 1 | kotlin.Byte | byte[] (item range: [-128~127]) | n |
| s | char[] | bytes | | kotlin.String | String.class | n |
| B | unsigned char | integer | 1 | Kotlin.UByte | byte[] (item range: [0~255]) | n |
| ? | _Bool | bool | 1 | | | |
| h | short | integer | 2 | kotlin.Short | "Int,Short, (range [-32768 , 32767])" | 2 |
| H | unsigned short | integer | 2 | kotlin.UShort | "Int,Short,UShort,(range [0 , 65535])" | 2 |
| i | int | integer | 4 | kotlin.Int | "[-2^31 , 2^31 - 1]" | 4 |
| l | long | integer | 4 | kotlin.Int | "[-2^31 , 2^31 - 1]" | 4 |
| I | unsigned int | integer | 4 | kotlin.UInt | "[0 , 2^32-1]" | |
| L | unsigned long | integer | 4 | kotlin.UInt | "[0 , 2^32-1]" | |
| q | long long | integer | 8 | kotlin.Long | | | |
| Q | unsigned long long | integer | 8 | kotlin.ULong | | |
| e | (7) | float | 2 | | | |
| f | float | float | 4 | | | |
| d | double | float | 8 | | | |
Loading…
Cancel
Save