diff options
author | Edoardo La Greca | 2025-08-18 21:09:11 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-08-18 21:09:11 +0200 |
commit | 7341ead2aade10ea1b833e94275277658741883a (patch) | |
tree | 46495f24c54278d50aa0da5046822fbe502f3f14 /src/main/kotlin/SizedInteger.kt | |
parent | 1e50cf9c224d03896f176f3718ff80ef1659e9c2 (diff) |
switch to multi-module project structure
Diffstat (limited to 'src/main/kotlin/SizedInteger.kt')
-rw-r--r-- | src/main/kotlin/SizedInteger.kt | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/src/main/kotlin/SizedInteger.kt b/src/main/kotlin/SizedInteger.kt deleted file mode 100644 index 48e4e25..0000000 --- a/src/main/kotlin/SizedInteger.kt +++ /dev/null @@ -1,36 +0,0 @@ -import java.math.BigInteger - -/** - * [SizedInteger] represents an unsigned integer number of arbitrary yet fixed length. It's useful for storing integers - * got from a connection as message fields. - * - * @param size The size of the field, measured in bytes. - * @param value The value of the field. - * - * @throws IllegalArgumentException if the size required to store the provided value is bigger than the provided size. - */ -class SizedInteger(val size: ULong, value: BigInteger) { - init { - if (!this.sizeOk(size, value)) { - throw IllegalArgumentException() - } - } - - constructor(size: ULong) : this(size, 0.toBigInteger()) - - /** - * @throws IllegalStateException on set if the declared size is not enough for the new value. - */ - var value = value - set(value) { - if (!this.sizeOk(value)) { - throw IllegalStateException() - } - } - - private fun sizeOk(size: ULong, value: BigInteger): Boolean { - val requiredSize = value.toByteArray().size.toUInt() - return requiredSize <= size - } - private fun sizeOk(value: BigInteger): Boolean = sizeOk(this.size, value) -}
\ No newline at end of file |