From f58a04c26fec1fa2c574ba953d6867a74c216b45 Mon Sep 17 00:00:00 2001 From: Juul Mobile Bot Date: Fri, 28 Jun 2024 09:12:46 +0000 Subject: [PATCH 1/2] Update plugin kotlinter to v4.4.0 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e3f8282..2811ac8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,6 @@ api = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = " dokka = { id = "org.jetbrains.dokka", version = "1.9.20" } kotlin-js = { id = "org.jetbrains.kotlin.js", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } -kotlinter = { id = "org.jmailen.kotlinter", version = "4.3.0" } +kotlinter = { id = "org.jmailen.kotlinter", version = "4.4.0" } kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } maven-publish = { id = "com.vanniktech.maven.publish", version = "0.29.0" } From c4b4d158899d673413afd9acca7f69bf2da7d7c9 Mon Sep 17 00:00:00 2001 From: Travis Wyatt Date: Sat, 6 Jul 2024 13:32:22 -0700 Subject: [PATCH 2/2] `./gradlew formatKotlin` --- koap/src/commonMain/kotlin/Encoder.kt | 3 +- koap/src/commonMain/kotlin/Message.kt | 63 ++++++++++++++++++++------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/koap/src/commonMain/kotlin/Encoder.kt b/koap/src/commonMain/kotlin/Encoder.kt index 9bbc559..ce42dd1 100644 --- a/koap/src/commonMain/kotlin/Encoder.kt +++ b/koap/src/commonMain/kotlin/Encoder.kt @@ -268,7 +268,8 @@ internal fun BufferedSink.writeOption(option: Format, preceding: Format?) { var write = false // 4 is max length shown for a `uint` in RFC 7252 Table 4: Options - (4 downTo 0).forEach { i -> // 4 downTo 0 used to write `uint` in network byte-order + // `4 downTo 0` used to write `uint` in network byte-order + (4 downTo 0).forEach { i -> val byte = (option.value shr (i * Byte.SIZE_BITS)).toInt() and 0xff // Per RFC 7252 3.2, begin writing at first non-zero byte. diff --git a/koap/src/commonMain/kotlin/Message.kt b/koap/src/commonMain/kotlin/Message.kt index 41e909f..71dd943 100644 --- a/koap/src/commonMain/kotlin/Message.kt +++ b/koap/src/commonMain/kotlin/Message.kt @@ -110,7 +110,9 @@ sealed class Message { } /** RFC 7252 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query */ - data class UriHost(val uri: String) : Option() { + data class UriHost( + val uri: String, + ) : Option() { init { require(uri.length in URI_HOST_LENGTH_RANGE) { "Uri-Host length of ${uri.length} is outside allowable range of $URI_HOST_LENGTH_RANGE" @@ -119,7 +121,9 @@ sealed class Message { } /** RFC 7252 5.10.1. Uri-Host, Uri-Port, Uri-Path, and Uri-Query */ - data class UriPort(val port: Long) : Option() { + data class UriPort( + val port: Long, + ) : Option() { init { require(port in URI_PORT_RANGE) { "Uri-Port value of $port is outside allowable range of $URI_PORT_RANGE" @@ -134,7 +138,9 @@ sealed class Message { * > encoding is performed. The value of a Uri-Path Option MUST NOT be "." or ".." (as the * > request URI must be resolved before parsing it into options). */ - data class UriPath(val uri: String) : Option() { + data class UriPath( + val uri: String, + ) : Option() { init { require(uri != "." && uri != "..") { "Uri-Path must not be \".\" or \"..\"" } require(uri.length in URI_PATH_LENGTH_RANGE) { @@ -148,7 +154,9 @@ sealed class Message { * * @see UriPath */ - data class UriQuery(val uri: String) : Option() { + data class UriQuery( + val uri: String, + ) : Option() { init { require(uri != "." && uri != "..") { "Uri-Query must not be \".\" or \"..\"" } require(uri.length in URI_QUERY_LENGTH_RANGE) { @@ -158,7 +166,9 @@ sealed class Message { } /** RFC 7252 5.10.2. Proxy-Uri and Proxy-Scheme */ - data class ProxyUri(val uri: String) : Option() { + data class ProxyUri( + val uri: String, + ) : Option() { init { require(uri.length in PROXY_URI_LENGTH_RANGE) { "Proxy-Uri length of ${uri.length} is outside allowable range of $PROXY_URI_LENGTH_RANGE" @@ -167,7 +177,9 @@ sealed class Message { } /** RFC 7252 5.10.2. Proxy-Uri and Proxy-Scheme */ - data class ProxyScheme(val uri: String) : Option() { + data class ProxyScheme( + val uri: String, + ) : Option() { init { require(uri.length in PROXY_SCHEME_LENGTH_RANGE) { "Proxy-Scheme length of ${uri.length} is outside allowable range of $PROXY_SCHEME_LENGTH_RANGE" @@ -176,7 +188,9 @@ sealed class Message { } /** RFC 7252 5.10.3. Content-Format */ - data class ContentFormat(val format: Long) : Option() { + data class ContentFormat( + val format: Long, + ) : Option() { init { require(format in CONTENT_FORMAT_RANGE) { "Content-Format of $format is outside allowable range of $CONTENT_FORMAT_RANGE" @@ -201,7 +215,9 @@ sealed class Message { } /** RFC 7252 5.10.4. Accept */ - data class Accept(val format: Long) : Option() { + data class Accept( + val format: Long, + ) : Option() { constructor(format: ContentFormat) : this(format.format) @@ -215,16 +231,21 @@ sealed class Message { } /** RFC 7252 5.10.5. Max-Age */ - data class MaxAge(val seconds: Long) : Option() { + data class MaxAge( + val seconds: Long, + ) : Option() { init { - require(seconds in MAX_AGE_RANGE) { // ~136.1 years + require(seconds in MAX_AGE_RANGE) { + // ~136.1 years "Max-Age of $seconds seconds is outside of allowable range of $MAX_AGE_RANGE" } } } /** RFC 7252 5.10.6. ETag */ - data class ETag(val etag: ByteArray) : Option() { + data class ETag( + val etag: ByteArray, + ) : Option() { init { require(etag.size in ETAG_SIZE_RANGE) { "ETag length of ${etag.size} is outside allowable range of $ETAG_SIZE_RANGE" @@ -240,7 +261,9 @@ sealed class Message { } /** RFC 7252 5.10.7. Location-Path and Location-Query */ - data class LocationPath(val uri: String) : Option() { + data class LocationPath( + val uri: String, + ) : Option() { init { require(uri.length in LOCATION_PATH_LENGTH_RANGE) { "Location-Path length of ${uri.length} is outside allowable range of $LOCATION_PATH_LENGTH_RANGE" @@ -249,7 +272,9 @@ sealed class Message { } /** RFC 7252 5.10.7. Location-Path and Location-Query */ - data class LocationQuery(val uri: String) : Option() { + data class LocationQuery( + val uri: String, + ) : Option() { init { require(uri.length in LOCATION_QUERY_LENGTH_RANGE) { "Location-Query length of ${uri.length} is outside allowable range of $LOCATION_QUERY_LENGTH_RANGE" @@ -258,7 +283,9 @@ sealed class Message { } /** RFC 7252 5.10.8.1. If-Match */ - data class IfMatch(val etag: ByteArray) : Option() { + data class IfMatch( + val etag: ByteArray, + ) : Option() { init { require(etag.size in IF_MATCH_SIZE_RANGE) { "If-Match length of ${etag.size} is outside allowable range of $IF_MATCH_SIZE_RANGE" @@ -279,7 +306,9 @@ sealed class Message { } /** RFC 7252 5.10.9. Size1 Option */ - data class Size1(val bytes: Long) : Option() { + data class Size1( + val bytes: Long, + ) : Option() { init { require(bytes in SIZE1_RANGE) { "Size1 of $bytes is outside allowable range of $SIZE1_RANGE" @@ -288,7 +317,9 @@ sealed class Message { } /** [RFC 7641 2. The Observe Option](https://tools.ietf.org/html/rfc7641#section-2) */ - data class Observe(val value: Long) : Option() { + data class Observe( + val value: Long, + ) : Option() { /** * Per [RFC 7641 2. The Observe Option](https://tools.ietf.org/html/rfc7641#section-2):