diff --git a/app_fenrir/build.gradle b/app_fenrir/build.gradle index 701245674..f4d1246cf 100644 --- a/app_fenrir/build.gradle +++ b/app_fenrir/build.gradle @@ -47,7 +47,7 @@ android { //noinspection ChromeOsAbiSupport abiFilters = targetAbi } - resConfigs "en", "ru" + androidResources.localeFilters = ["en", "ru"] } lint { @@ -67,6 +67,7 @@ android { "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", "-opt-in=kotlinx.serialization.internal.CoreFriendModuleApi", + "-opt-in=kotlinx.serialization.SealedSerializationApi", "-opt-in=kotlinx.serialization.InternalSerializationApi", "-opt-in=kotlin.RequiresOptIn", "-opt-in=kotlin.ExperimentalStdlibApi"] } diff --git a/app_fenrir/src/main/AndroidManifest.xml b/app_fenrir/src/main/AndroidManifest.xml index bfcef0fe1..90c9b6961 100644 --- a/app_fenrir/src/main/AndroidManifest.xml +++ b/app_fenrir/src/main/AndroidManifest.xml @@ -358,7 +358,7 @@ android:theme="@style/App.DayNight.Swipes" android:windowSoftInputMode="adjustResize|stateHidden"> - + diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Extensions.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Extensions.kt index 9390f6f19..ed097dd26 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Extensions.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Extensions.kt @@ -19,12 +19,22 @@ import android.view.View import androidx.annotation.ColorInt import androidx.core.database.getBlobOrNull import androidx.core.database.getStringOrNull -import dev.ragnarok.fenrir.util.serializeble.json.Json +import kotlinx.serialization.json.Json import okhttp3.ResponseBody import java.io.Serializable import kotlin.contracts.contract val kJson: Json by lazy { Json { ignoreUnknownKeys = true; isLenient = true } } +val kJsonPretty: Json by lazy { + Json { + ignoreUnknownKeys = true; isLenient = true; prettyPrint = true + } +} +val kJsonNotPretty: Json by lazy { + Json { + ignoreUnknownKeys = true; isLenient = true; prettyPrint = false + } +} fun SQLiteDatabase.query( tableName: String, diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/FcmListenerService.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/FcmListenerService.kt index dd34b192f..1bb6e618f 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/FcmListenerService.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/FcmListenerService.kt @@ -24,7 +24,6 @@ import dev.ragnarok.fenrir.settings.Settings import dev.ragnarok.fenrir.util.Logger import dev.ragnarok.fenrir.util.PersistentLogger import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.hiddenIO -import dev.ragnarok.fenrir.util.serializeble.json.Json import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.builtins.serializer @@ -60,9 +59,7 @@ class FcmListenerService : FirebaseMessagingService() { if (Constants.IS_DEBUG) { Logger.d( TAG, - "onMessage, from: " + message.from + ", pushType: " + pushType + ", data: " + Json { - prettyPrint = true - }.encodeToString( + "onMessage, from: " + message.from + ", pushType: " + pushType + ", data: " + kJsonPretty.encodeToString( MapSerializer(String.serializer(), String.serializer()), message.data ) @@ -71,9 +68,7 @@ class FcmListenerService : FirebaseMessagingService() { PersistentLogger.logThrowable( "Push received", Exception( - "Key: $pushType, Dump: " + Json { - prettyPrint = true - }.encodeToString( + "Key: $pushType, Dump: " + kJsonPretty.encodeToString( MapSerializer(String.serializer(), String.serializer()), message.data ) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/activity/DeltaOwnerActivity.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/activity/DeltaOwnerActivity.kt index 3f0c26def..a522d7e00 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/activity/DeltaOwnerActivity.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/activity/DeltaOwnerActivity.kt @@ -28,6 +28,7 @@ import dev.ragnarok.fenrir.activity.slidr.model.SlidrPosition import dev.ragnarok.fenrir.fragment.absownerslist.OwnersAdapter import dev.ragnarok.fenrir.getParcelableCompat import dev.ragnarok.fenrir.kJson +import dev.ragnarok.fenrir.kJsonPretty import dev.ragnarok.fenrir.listener.AppStyleable import dev.ragnarok.fenrir.model.DeltaOwner import dev.ragnarok.fenrir.model.Owner @@ -51,9 +52,8 @@ import dev.ragnarok.fenrir.util.Utils import dev.ragnarok.fenrir.util.Utils.hasVanillaIceCreamTarget import dev.ragnarok.fenrir.util.coroutines.CancelableJob import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.fromIOToMain -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.decodeFromBufferedSource import dev.ragnarok.fenrir.util.toast.CustomToast +import kotlinx.serialization.json.decodeFromBufferedSource import okio.buffer import okio.source import java.io.File @@ -135,7 +135,7 @@ class DeltaOwnerActivity : AppCompatActivity(), PlaceProvider, AppStyleable { ) var out: FileOutputStream? = null try { - val bytes = Json { prettyPrint = true }.encodeToString( + val bytes = kJsonPretty.encodeToString( DeltaOwner.serializer(), delta ).toByteArray( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AbsDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AbsDtoAdapter.kt index c9667e456..0eee9ae0b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AbsDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AbsDtoAdapter.kt @@ -2,25 +2,25 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.Constants import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonArray -import dev.ragnarok.fenrir.util.serializeble.json.JsonDecoder -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonNull -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.JsonPrimitive -import dev.ragnarok.fenrir.util.serializeble.json.booleanOrNull -import dev.ragnarok.fenrir.util.serializeble.json.doubleOrNull -import dev.ragnarok.fenrir.util.serializeble.json.floatOrNull -import dev.ragnarok.fenrir.util.serializeble.json.intOrNull -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonPrimitive -import dev.ragnarok.fenrir.util.serializeble.json.longOrNull -import dev.ragnarok.fenrir.util.serializeble.msgpack.internal.BasicMsgPackDecoder import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.buildClassSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.booleanOrNull +import kotlinx.serialization.json.doubleOrNull +import kotlinx.serialization.json.floatOrNull +import kotlinx.serialization.json.intOrNull +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonPrimitive +import kotlinx.serialization.json.longOrNull +import kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder import kotlin.contracts.contract abstract class AbsDtoAdapter(name: String) : KSerializer { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ArticleDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ArticleDtoAdapter.kt index 7c54cdbc9..918ffba0a 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ArticleDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ArticleDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiArticle import dev.ragnarok.fenrir.api.model.VKApiPhoto import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement +import kotlinx.serialization.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.jsonObject class ArticleDtoAdapter : AbsDtoAdapter("VKApiArticle") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AttachmentsDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AttachmentsDtoAdapter.kt index b98447455..3bbefbba7 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AttachmentsDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AttachmentsDtoAdapter.kt @@ -5,10 +5,10 @@ import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.util.Utils -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class AttachmentsDtoAdapter : AbsDtoAdapter("VKApiAttachments") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AttachmentsEntryDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AttachmentsEntryDtoAdapter.kt index 1d29edecd..d52006166 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AttachmentsEntryDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AttachmentsEntryDtoAdapter.kt @@ -4,8 +4,8 @@ import dev.ragnarok.fenrir.api.adapters.AttachmentsDtoAdapter.Companion.parse import dev.ragnarok.fenrir.api.model.VKApiAttachments import dev.ragnarok.fenrir.api.model.VKApiNotSupported import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class AttachmentsEntryDtoAdapter : AbsDtoAdapter("VKApiAttachments.Entry") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AudioDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AudioDtoAdapter.kt index b61e3a433..c7e22ca97 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AudioDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AudioDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiAudio import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class AudioDtoAdapter : AbsDtoAdapter("VKApiAudio") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AudioPlaylistDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AudioPlaylistDtoAdapter.kt index 88ad0777d..436a23e5d 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AudioPlaylistDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/AudioPlaylistDtoAdapter.kt @@ -1,9 +1,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiAudioPlaylist -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class AudioPlaylistDtoAdapter : AbsDtoAdapter("VKApiAudioPlaylist") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatDtoAdapter.kt index b20b5b6fa..e2ac5790d 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatDtoAdapter.kt @@ -6,10 +6,10 @@ import dev.ragnarok.fenrir.api.model.VKApiCommunity import dev.ragnarok.fenrir.api.model.VKApiUser import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject -import dev.ragnarok.fenrir.util.serializeble.json.long +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.long class ChatDtoAdapter : AbsDtoAdapter("VKApiChat") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatJsonResponseDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatJsonResponseDtoAdapter.kt index 01879d27c..d4fcc116d 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatJsonResponseDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatJsonResponseDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiMessage import dev.ragnarok.fenrir.api.model.local_json.ChatJsonResponse import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class ChatJsonResponseDtoAdapter : AbsDtoAdapter("ChatJsonResponse") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatUserDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatUserDtoAdapter.kt index ac4e54ec1..8c0edc46b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatUserDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatUserDtoAdapter.kt @@ -3,8 +3,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.ChatUserDto import dev.ragnarok.fenrir.api.model.VKApiUser import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class ChatUserDtoAdapter : AbsDtoAdapter("ChatUserDto") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatsInfoDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatsInfoDtoAdapter.kt index 7d622b7da..e6b370662 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatsInfoDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ChatsInfoDtoAdapter.kt @@ -3,8 +3,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiChat import dev.ragnarok.fenrir.api.model.response.ChatsInfoResponse import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray class ChatsInfoDtoAdapter : AbsDtoAdapter("ChatsInfoResponse") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CommentDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CommentDtoAdapter.kt index fe32791bc..abce00f91 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CommentDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CommentDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiAttachments import dev.ragnarok.fenrir.api.model.VKApiComment import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class CommentDtoAdapter : AbsDtoAdapter("VKApiComment") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CommunityDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CommunityDtoAdapter.kt index 8c9b17d74..a354d2933 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CommunityDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CommunityDtoAdapter.kt @@ -4,9 +4,9 @@ import dev.ragnarok.fenrir.api.Fields import dev.ragnarok.fenrir.api.model.* import dev.ragnarok.fenrir.api.util.VKStringUtils import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject import java.util.Locale import kotlin.math.abs diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CustomCommentsResponseDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CustomCommentsResponseDtoAdapter.kt index a97202bfc..b51b4b7ba 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CustomCommentsResponseDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/CustomCommentsResponseDtoAdapter.kt @@ -2,10 +2,10 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.response.CustomCommentsResponse import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.intOrNull -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject -import dev.ragnarok.fenrir.util.serializeble.json.jsonPrimitive +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.intOrNull +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive class CustomCommentsResponseDtoAdapter : AbsDtoAdapter("CustomCommentsResponse") { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/DocsEntryDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/DocsEntryDtoAdapter.kt index ac5c064c7..234af37ef 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/DocsEntryDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/DocsEntryDtoAdapter.kt @@ -2,8 +2,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiDoc import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class DocsEntryDtoAdapter : AbsDtoAdapter("VKApiDoc.Entry") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FaveLinkDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FaveLinkDtoAdapter.kt index dc069095d..97bbf8f69 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FaveLinkDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FaveLinkDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.FaveLinkDto import dev.ragnarok.fenrir.api.model.VKApiPhoto import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonObject class FaveLinkDtoAdapter : AbsDtoAdapter("FaveLinkDto") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackDtoAdapter.kt index 56b340d31..1f9b020d2 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackDtoAdapter.kt @@ -3,10 +3,10 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.* import dev.ragnarok.fenrir.api.model.feedback.* import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.decodeFromJsonElementOrNull -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.decodeFromJsonElementOrNull +import kotlinx.serialization.json.jsonObject class FeedbackDtoAdapter : AbsDtoAdapter("VKApiBaseFeedback") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackUserArrayDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackUserArrayDtoAdapter.kt index 3818e8e67..639c3f2c1 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackUserArrayDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackUserArrayDtoAdapter.kt @@ -2,9 +2,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.feedback.UserArray import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class FeedbackUserArrayDtoAdapter : AbsDtoAdapter("UserArray") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackVKOfficialDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackVKOfficialDtoAdapter.kt index 0e4f32f7e..e27f994e4 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackVKOfficialDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/FeedbackVKOfficialDtoAdapter.kt @@ -12,8 +12,8 @@ import dev.ragnarok.fenrir.model.FeedbackVKOfficialList import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.orZero import dev.ragnarok.fenrir.util.Utils -import dev.ragnarok.fenrir.util.serializeble.json.* import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.json.* class FeedbackVKOfficialDtoAdapter : AbsDtoAdapter("FeedbackVKOfficialList") { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/GeoDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/GeoDtoAdapter.kt index 7a6460dd7..794dfe67d 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/GeoDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/GeoDtoAdapter.kt @@ -1,8 +1,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiGeo -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class GeoDtoAdapter : AbsDtoAdapter("VKApiGeo") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/GroupSettingsDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/GroupSettingsDtoAdapter.kt index 45789593f..ea80659f6 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/GroupSettingsDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/GroupSettingsDtoAdapter.kt @@ -2,11 +2,11 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.GroupSettingsDto import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.int -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject -import dev.ragnarok.fenrir.util.serializeble.json.jsonPrimitive +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.int +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive class GroupSettingsDtoAdapter : AbsDtoAdapter("GroupSettingsDto") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/JsonStringDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/JsonStringDtoAdapter.kt index 856a96212..941266639 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/JsonStringDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/JsonStringDtoAdapter.kt @@ -1,8 +1,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiJsonString -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class JsonStringDtoAdapter : AbsDtoAdapter("VKApiJsonString") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LikesListDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LikesListDtoAdapter.kt index 3dc55f034..d3c40101e 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LikesListDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LikesListDtoAdapter.kt @@ -7,9 +7,9 @@ import dev.ragnarok.fenrir.api.model.response.LikesListResponse import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.orZero import dev.ragnarok.fenrir.requireNonNull -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class LikesListDtoAdapter : AbsDtoAdapter("LikesListResponse") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LongpollUpdateDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LongpollUpdateDtoAdapter.kt index a66158906..24ad82e22 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LongpollUpdateDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LongpollUpdateDtoAdapter.kt @@ -10,7 +10,7 @@ import dev.ragnarok.fenrir.model.Peer import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.orZero import dev.ragnarok.fenrir.util.Utils -import dev.ragnarok.fenrir.util.serializeble.json.* +import kotlinx.serialization.json.* import java.util.Collections class LongpollUpdateDtoAdapter : AbsDtoAdapter("AbsLongpollEvent?") { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LongpollUpdatesDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LongpollUpdatesDtoAdapter.kt index f11b9625b..56a8a1c52 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LongpollUpdatesDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LongpollUpdatesDtoAdapter.kt @@ -4,9 +4,9 @@ import dev.ragnarok.fenrir.api.model.longpoll.AbsLongpollEvent import dev.ragnarok.fenrir.api.model.longpoll.VKApiLongpollUpdates import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.util.Logger -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class LongpollUpdatesDtoAdapter : AbsDtoAdapter("VkApiLongpollUpdates") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LyricsDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LyricsDtoAdapter.kt index 1ce7c27be..eeef1469c 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LyricsDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/LyricsDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiLyrics import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.util.AppTextUtils -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class LyricsDtoAdapter : AbsDtoAdapter("VKApiLyrics") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/MarketDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/MarketDtoAdapter.kt index aa3ef6a30..7c94654e7 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/MarketDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/MarketDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiMarket import dev.ragnarok.fenrir.api.model.VKApiPhoto import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class MarketDtoAdapter : AbsDtoAdapter("VKApiMarket") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/MessageDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/MessageDtoAdapter.kt index c87f93a0c..cacc0d170 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/MessageDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/MessageDtoAdapter.kt @@ -5,9 +5,9 @@ import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment import dev.ragnarok.fenrir.api.util.VKStringUtils import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class MessageDtoAdapter : AbsDtoAdapter("VKApiMessage") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NarrativesDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NarrativesDtoAdapter.kt index c7caa18f9..e95eefad9 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NarrativesDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NarrativesDtoAdapter.kt @@ -2,10 +2,10 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiNarratives import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.int -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.int +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class NarrativesDtoAdapter : AbsDtoAdapter("VKApiNarratives") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NewsDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NewsDtoAdapter.kt index d11e17f01..4be871f5e 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NewsDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NewsDtoAdapter.kt @@ -4,10 +4,10 @@ import dev.ragnarok.fenrir.api.model.* import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject -import dev.ragnarok.fenrir.util.serializeble.json.long +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.long class NewsDtoAdapter : AbsDtoAdapter("VKApiNews") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NewsfeedCommentDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NewsfeedCommentDtoAdapter.kt index 56475564e..ee6ea2986 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NewsfeedCommentDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/NewsfeedCommentDtoAdapter.kt @@ -3,8 +3,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.* import dev.ragnarok.fenrir.api.model.response.NewsfeedCommentsResponse.* import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class NewsfeedCommentDtoAdapter : AbsDtoAdapter("Dto") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PhotoAlbumDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PhotoAlbumDtoAdapter.kt index f4c6fb0f0..3c0927eb0 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PhotoAlbumDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PhotoAlbumDtoAdapter.kt @@ -5,9 +5,9 @@ import dev.ragnarok.fenrir.api.model.VKApiPhotoAlbum import dev.ragnarok.fenrir.api.model.VKApiPrivacy import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class PhotoAlbumDtoAdapter : AbsDtoAdapter("VKApiPhotoAlbum") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PhotoDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PhotoDtoAdapter.kt index d69e5457e..15f7bb005 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PhotoDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PhotoDtoAdapter.kt @@ -5,9 +5,9 @@ import dev.ragnarok.fenrir.api.model.PhotoSizeDto import dev.ragnarok.fenrir.api.model.VKApiPhoto import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class PhotoDtoAdapter : AbsDtoAdapter("VKApiPhoto") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PostDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PostDtoAdapter.kt index 446413271..55074fb07 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PostDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PostDtoAdapter.kt @@ -5,9 +5,9 @@ import dev.ragnarok.fenrir.api.model.VKApiPost.Type.DONUT import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class PostDtoAdapter : AbsDtoAdapter("VKApiPost") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PostSourceDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PostSourceDtoAdapter.kt index 80556d94d..ef101fdb7 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PostSourceDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PostSourceDtoAdapter.kt @@ -1,8 +1,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiPostSource -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class PostSourceDtoAdapter : AbsDtoAdapter("VKApiPostSource") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PrivacyDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PrivacyDtoAdapter.kt index e377d364f..3ccd611b0 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PrivacyDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/PrivacyDtoAdapter.kt @@ -1,9 +1,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiPrivacy -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class PrivacyDtoAdapter : AbsDtoAdapter("VKApiPrivacy") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ProcessAuthCodeDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ProcessAuthCodeDtoAdapter.kt index adaf35144..2ae536485 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ProcessAuthCodeDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ProcessAuthCodeDtoAdapter.kt @@ -1,8 +1,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiProcessAuthCode -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class ProcessAuthCodeDtoAdapter : AbsDtoAdapter("VKApiProcessAuthCode") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ProfileInfoResponseDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ProfileInfoResponseDtoAdapter.kt index 3e323c809..dabe3d263 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ProfileInfoResponseDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ProfileInfoResponseDtoAdapter.kt @@ -1,8 +1,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiProfileInfoResponse -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class ProfileInfoResponseDtoAdapter : AbsDtoAdapter("VKApiProfileInfoResponse") { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ReactionAssetDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ReactionAssetDtoAdapter.kt index 9b1d79a4b..fc737e806 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ReactionAssetDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ReactionAssetDtoAdapter.kt @@ -1,8 +1,8 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiReactionAsset -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class ReactionAssetDtoAdapter : AbsDtoAdapter("VKApiReactionAsset") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/SchoolClazzDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/SchoolClazzDtoAdapter.kt index 90489ec91..59cabb803 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/SchoolClazzDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/SchoolClazzDtoAdapter.kt @@ -1,10 +1,10 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.database.SchoolClazzDto -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.intOrNull -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonPrimitive +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.intOrNull +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonPrimitive class SchoolClazzDtoAdapter : AbsDtoAdapter("SchoolClazzDto") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ServicePlaylistResponseDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ServicePlaylistResponseDtoAdapter.kt index 986ea7123..48223c52f 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ServicePlaylistResponseDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ServicePlaylistResponseDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.VKApiAudioPlaylist import dev.ragnarok.fenrir.api.model.response.ServicePlaylistResponse import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class ServicePlaylistResponseDtoAdapter : AbsDtoAdapter("ServicePlaylistResponse") { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/StoryDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/StoryDtoAdapter.kt index e0c437b4b..4cfaab9eb 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/StoryDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/StoryDtoAdapter.kt @@ -4,8 +4,8 @@ import dev.ragnarok.fenrir.api.model.VKApiPhoto import dev.ragnarok.fenrir.api.model.VKApiStory import dev.ragnarok.fenrir.api.model.VKApiVideo import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class StoryDtoAdapter : AbsDtoAdapter("VKApiStory") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/TopicDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/TopicDtoAdapter.kt index d4c0eb1e9..1f55fc2a7 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/TopicDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/TopicDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters import dev.ragnarok.fenrir.api.model.CommentsDto import dev.ragnarok.fenrir.api.model.VKApiTopic import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.intOrNull -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.intOrNull +import kotlinx.serialization.json.jsonObject class TopicDtoAdapter : AbsDtoAdapter("VKApiTopic") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/UserDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/UserDtoAdapter.kt index bef77c8c5..4e4e5b55e 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/UserDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/UserDtoAdapter.kt @@ -5,9 +5,9 @@ import dev.ragnarok.fenrir.api.model.* import dev.ragnarok.fenrir.api.util.VKStringUtils import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class UserDtoAdapter : AbsDtoAdapter("VKApiUser") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/VideoAlbumDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/VideoAlbumDtoAdapter.kt index 030fa0dbf..72e1d547c 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/VideoAlbumDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/VideoAlbumDtoAdapter.kt @@ -4,10 +4,10 @@ import dev.ragnarok.fenrir.api.model.VKApiPrivacy import dev.ragnarok.fenrir.api.model.VKApiVideoAlbum import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.intOrNull -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.intOrNull +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class VideoAlbumDtoAdapter : AbsDtoAdapter("VKApiVideoAlbum") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/VideoDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/VideoDtoAdapter.kt index 89b4b2636..22b5e80fb 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/VideoDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/VideoDtoAdapter.kt @@ -7,9 +7,9 @@ import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.orZero import dev.ragnarok.fenrir.util.Utils -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class VideoDtoAdapter : AbsDtoAdapter("VKApiVideo") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ViewersListDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ViewersListDtoAdapter.kt index eaeaad9ec..625e449e7 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ViewersListDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/ViewersListDtoAdapter.kt @@ -5,9 +5,9 @@ import dev.ragnarok.fenrir.api.model.response.ViewersListResponse import dev.ragnarok.fenrir.kJson import dev.ragnarok.fenrir.orZero import dev.ragnarok.fenrir.requireNonNull -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class ViewersListDtoAdapter : AbsDtoAdapter("ViewersListAdapter") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/catalog_v2_audio/VKApiCatalogV2LinkDtoAdapter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/catalog_v2_audio/VKApiCatalogV2LinkDtoAdapter.kt index 4a2f4a00e..d4c9016da 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/catalog_v2_audio/VKApiCatalogV2LinkDtoAdapter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/adapters/catalog_v2_audio/VKApiCatalogV2LinkDtoAdapter.kt @@ -3,9 +3,9 @@ package dev.ragnarok.fenrir.api.adapters.catalog_v2_audio import dev.ragnarok.fenrir.api.adapters.AbsDtoAdapter import dev.ragnarok.fenrir.api.model.catalog_v2_audio.VKApiCatalogV2Link import dev.ragnarok.fenrir.orZero -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject class VKApiCatalogV2LinkDtoAdapter : AbsDtoAdapter("VKApiCatalogV2Link") { @Throws(Exception::class) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/AbsApi.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/AbsApi.kt index cd0b6ecab..4261b3f4f 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/AbsApi.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/AbsApi.kt @@ -22,14 +22,14 @@ import dev.ragnarok.fenrir.requireNonNull import dev.ragnarok.fenrir.service.ApiErrorCodes import dev.ragnarok.fenrir.settings.Settings import dev.ragnarok.fenrir.util.refresh.RefreshToken -import dev.ragnarok.fenrir.util.serializeble.json.decodeFromBufferedSource -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flatMapConcat import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.single import kotlinx.serialization.KSerializer +import kotlinx.serialization.json.decodeFromBufferedSource +import kotlinx.serialization.msgpack.MsgPack import okhttp3.FormBody import okhttp3.Request import kotlin.coroutines.cancellation.CancellationException diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/PollsApi.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/PollsApi.kt index 1fa549b1d..702303b81 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/PollsApi.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/PollsApi.kt @@ -10,12 +10,12 @@ import dev.ragnarok.fenrir.api.services.IPollsService import dev.ragnarok.fenrir.util.Utils import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.checkInt import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.emptyListFlow -import dev.ragnarok.fenrir.util.serializeble.json.Json import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flatMapConcat import kotlinx.coroutines.flow.map import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.json.Json internal class PollsApi(accountId: Long, provider: IServiceProvider) : AbsApi(accountId, provider), IPollsApi { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/rest/SimplePostHttp.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/rest/SimplePostHttp.kt index c42875367..2fb2bedd7 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/rest/SimplePostHttp.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/rest/SimplePostHttp.kt @@ -8,11 +8,11 @@ import dev.ragnarok.fenrir.ifNonNull import dev.ragnarok.fenrir.isJson import dev.ragnarok.fenrir.isMsgPack import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.decodeFromBufferedSource -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.serialization.KSerializer +import kotlinx.serialization.json.decodeFromBufferedSource +import kotlinx.serialization.msgpack.MsgPack import okhttp3.FormBody import okhttp3.MultipartBody import okhttp3.OkHttpClient diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/AttachmentsStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/AttachmentsStorage.kt index f8e30120c..bbf985f0e 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/AttachmentsStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/AttachmentsStorage.kt @@ -23,9 +23,9 @@ import dev.ragnarok.fenrir.util.Pair import dev.ragnarok.fenrir.util.Pair.Companion.create import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack internal class AttachmentsStorage(base: AppStorages) : AbsStorage(base), IAttachmentsStorage { override fun attachDbos( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/CommentsStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/CommentsStorage.kt index f66d8b1a1..b22bada22 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/CommentsStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/CommentsStorage.kt @@ -32,13 +32,13 @@ import dev.ragnarok.fenrir.util.Unixtime.now import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.createPublishSubject import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.single import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.msgpack.MsgPack internal class CommentsStorage(base: AppStorages) : AbsStorage(base), ICommentsStorage { private val minorUpdatesPublisher = createPublishSubject() diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/DialogsStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/DialogsStorage.kt index f7f14c595..87de0c5f7 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/DialogsStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/DialogsStorage.kt @@ -42,10 +42,10 @@ import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.createPublishSubject import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.emptyListFlow import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.myEmit -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack internal class DialogsStorage(base: AppStorages) : AbsStorage(base), IDialogsStorage { private val unreadDialogsCounter = createPublishSubject>() diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/DocsStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/DocsStorage.kt index fb329fc4f..4538e8491 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/DocsStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/DocsStorage.kt @@ -22,9 +22,9 @@ import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.util.Exestime.log import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack internal class DocsStorage(base: AppStorages) : AbsStorage(base), IDocsStorage { override fun get(criteria: DocsCriteria): Flow> { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FaveStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FaveStorage.kt index 290883715..2bd147dad 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FaveStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FaveStorage.kt @@ -43,10 +43,10 @@ import dev.ragnarok.fenrir.model.criteria.FaveProductsCriteria import dev.ragnarok.fenrir.model.criteria.FaveVideosCriteria import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.single +import kotlinx.serialization.msgpack.MsgPack import kotlin.math.abs internal class FaveStorage(mRepositoryContext: AppStorages) : AbsStorage(mRepositoryContext), diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FeedStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FeedStorage.kt index 20e76df25..66d42b8ae 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FeedStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FeedStorage.kt @@ -30,10 +30,10 @@ import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.util.Utils.join import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.msgpack.MsgPack internal class FeedStorage(base: AppStorages) : AbsStorage(base), IFeedStorage { private val storeLock = Any() diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FeedbackStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FeedbackStorage.kt index 06d48fe48..51bcb4495 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FeedbackStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/FeedbackStorage.kt @@ -15,9 +15,9 @@ import dev.ragnarok.fenrir.model.FeedbackVKOfficial import dev.ragnarok.fenrir.model.criteria.NotificationsCriteria import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack internal class FeedbackStorage(context: AppStorages) : AbsStorage(context), IFeedbackStorage { override fun insert( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/MessagesStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/MessagesStorage.kt index b384e717a..a43d89e3b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/MessagesStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/MessagesStorage.kt @@ -40,7 +40,6 @@ import dev.ragnarok.fenrir.util.Pair.Companion.create import dev.ragnarok.fenrir.util.Utils.join import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map @@ -48,6 +47,7 @@ import kotlinx.coroutines.flow.single import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.msgpack.MsgPack internal class MessagesStorage(base: AppStorages) : AbsStorage(base), IMessagesStorage { override fun insertPeerDbos( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/OwnersStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/OwnersStorage.kt index ffa2eb54c..28c0b57f1 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/OwnersStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/OwnersStorage.kt @@ -46,10 +46,10 @@ import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.createPublishSubject import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.emptyListFlow import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.emptyTaskFlow import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack internal class OwnersStorage(context: AppStorages) : AbsStorage(context), IOwnersStorage { private val banActionsPublisher = createPublishSubject() diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/PhotoAlbumsStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/PhotoAlbumsStorage.kt index d2d691464..69c85277b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/PhotoAlbumsStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/PhotoAlbumsStorage.kt @@ -22,9 +22,9 @@ import dev.ragnarok.fenrir.util.Optional import dev.ragnarok.fenrir.util.Optional.Companion.wrap import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack internal class PhotoAlbumsStorage(base: AppStorages) : AbsStorage(base), IPhotoAlbumsStorage { override fun findAlbumById( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/PhotosStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/PhotosStorage.kt index d9ebc562a..8b4f61975 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/PhotosStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/PhotosStorage.kt @@ -24,9 +24,9 @@ import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.requireNonNull import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack internal class PhotosStorage(base: AppStorages) : AbsStorage(base), IPhotosStorage { override fun insertPhotosRx( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/StickersStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/StickersStorage.kt index b6cae40dd..3730110d2 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/StickersStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/StickersStorage.kt @@ -21,11 +21,11 @@ import dev.ragnarok.fenrir.settings.Settings import dev.ragnarok.fenrir.util.Exestime.log import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.msgpack.MsgPack internal class StickersStorage(base: AppStorages) : AbsStorage(base), IStickersStorage { override fun storeStickerSets(accountId: Long, sets: List): Flow { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/TempDataStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/TempDataStorage.kt index e85e5eccc..7ed28b089 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/TempDataStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/TempDataStorage.kt @@ -28,11 +28,11 @@ import dev.ragnarok.fenrir.settings.Settings import dev.ragnarok.fenrir.util.Exestime.log import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.emptyTaskFlow import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.msgpack.MsgPack class TempDataStorage internal constructor(context: Context) : ITempDataStorage { private val app: Context = context.applicationContext diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/TopicsStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/TopicsStorage.kt index f069a791e..7379b8fe8 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/TopicsStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/TopicsStorage.kt @@ -24,9 +24,9 @@ import dev.ragnarok.fenrir.model.criteria.TopicsCriteria import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack import kotlin.math.abs internal class TopicsStorage(base: AppStorages) : AbsStorage(base), ITopicsStore { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/VideoAlbumsStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/VideoAlbumsStorage.kt index a8e3f834f..e10f7dfdf 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/VideoAlbumsStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/VideoAlbumsStorage.kt @@ -19,9 +19,9 @@ import dev.ragnarok.fenrir.model.VideoAlbumCriteria import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack internal class VideoAlbumsStorage(base: AppStorages) : AbsStorage(base), IVideoAlbumsStorage { override fun findByCriteria(criteria: VideoAlbumCriteria): Flow> { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/VideoStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/VideoStorage.kt index 62f841a7c..0ee1a69ba 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/VideoStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/VideoStorage.kt @@ -20,9 +20,9 @@ import dev.ragnarok.fenrir.model.VideoCriteria import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.msgpack.MsgPack internal class VideoStorage(base: AppStorages) : AbsStorage(base), IVideoStorage { override fun findByCriteria(criteria: VideoCriteria): Flow> { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/WallStorage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/WallStorage.kt index aa9b13023..6a966c2c3 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/WallStorage.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/impl/WallStorage.kt @@ -34,11 +34,11 @@ import dev.ragnarok.fenrir.util.Optional import dev.ragnarok.fenrir.util.Optional.Companion.wrap import dev.ragnarok.fenrir.util.Utils.safeCountOf import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flatMapConcat import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map +import kotlinx.serialization.msgpack.MsgPack internal class WallStorage(base: AppStorages) : AbsStorage(base), IWallStorage { override fun storeWallEntities( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/serialize/Serializers.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/serialize/Serializers.kt index c03677471..7c4057da5 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/serialize/Serializers.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/db/serialize/Serializers.kt @@ -1,7 +1,7 @@ package dev.ragnarok.fenrir.db.serialize import dev.ragnarok.fenrir.model.Photo -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack +import kotlinx.serialization.msgpack.MsgPack object Serializers { val PHOTOS_SERIALIZER: ISerializeAdapter = object : ISerializeAdapter { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/domain/impl/MessagesRepository.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/domain/impl/MessagesRepository.kt index c0fa935d1..2132fa64a 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/domain/impl/MessagesRepository.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/domain/impl/MessagesRepository.kt @@ -130,7 +130,6 @@ import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.sharedFlowToMain import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.syncSingleSafe import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.toFlow import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.toFlowThrowable -import dev.ragnarok.fenrir.util.serializeble.json.decodeFromBufferedSource import dev.ragnarok.fenrir.util.toast.CustomToast.Companion.createCustomToast import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.asCoroutineDispatcher @@ -144,6 +143,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onCompletion import kotlinx.coroutines.flow.single +import kotlinx.serialization.json.decodeFromBufferedSource import okio.buffer import okio.source import java.io.File diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/PreferencesFragment.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/PreferencesFragment.kt index 855ce7e70..48efa6773 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/PreferencesFragment.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/PreferencesFragment.kt @@ -93,12 +93,12 @@ import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.fromIOToMain import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.hiddenIO import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.toMain import dev.ragnarok.fenrir.util.refresh.RefreshToken -import dev.ragnarok.fenrir.util.serializeble.prefs.Preferences import dev.ragnarok.fenrir.util.toast.CustomSnackbars import dev.ragnarok.fenrir.util.toast.CustomToast.Companion.createCustomToast import dev.ragnarok.fenrir.view.MySearchView import dev.ragnarok.fenrir.view.natives.animation.ThorVGLottieView import dev.ragnarok.fenrir.view.navigation.AbsNavigationView +import kotlinx.serialization.prefs.Preferences import java.io.File import java.io.FileOutputStream import java.io.IOException diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/accounts/AccountsPresenter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/accounts/AccountsPresenter.kt index 898e25922..728f6aeca 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/accounts/AccountsPresenter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/accounts/AccountsPresenter.kt @@ -33,6 +33,7 @@ import dev.ragnarok.fenrir.exception.UnauthorizedException import dev.ragnarok.fenrir.fragment.base.RxSupportPresenter import dev.ragnarok.fenrir.isMsgPack import dev.ragnarok.fenrir.kJson +import dev.ragnarok.fenrir.kJsonPretty import dev.ragnarok.fenrir.longpoll.LongpollInstance import dev.ragnarok.fenrir.model.Account import dev.ragnarok.fenrir.model.IOwnersBundle @@ -57,19 +58,6 @@ import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.inMainThread import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.isActive import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.syncSingle import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.syncSingleSafe -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.JsonArrayBuilder -import dev.ragnarok.fenrir.util.serializeble.json.JsonObjectBuilder -import dev.ragnarok.fenrir.util.serializeble.json.contentOrNull -import dev.ragnarok.fenrir.util.serializeble.json.decodeFromBufferedSource -import dev.ragnarok.fenrir.util.serializeble.json.intOrNull -import dev.ragnarok.fenrir.util.serializeble.json.jsonArray -import dev.ragnarok.fenrir.util.serializeble.json.jsonObject -import dev.ragnarok.fenrir.util.serializeble.json.jsonPrimitive -import dev.ragnarok.fenrir.util.serializeble.json.long -import dev.ragnarok.fenrir.util.serializeble.json.longOrNull -import dev.ragnarok.fenrir.util.serializeble.json.put -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import dev.ragnarok.fenrir.util.toast.CustomToast import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow @@ -78,6 +66,18 @@ import kotlinx.coroutines.flow.flatMapConcat import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.json.JsonArrayBuilder +import kotlinx.serialization.json.JsonObjectBuilder +import kotlinx.serialization.json.contentOrNull +import kotlinx.serialization.json.decodeFromBufferedSource +import kotlinx.serialization.json.intOrNull +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive +import kotlinx.serialization.json.long +import kotlinx.serialization.json.longOrNull +import kotlinx.serialization.json.put +import kotlinx.serialization.msgpack.MsgPack import okhttp3.FormBody import okhttp3.Request import okio.buffer @@ -377,7 +377,7 @@ class AccountsPresenter(savedInstanceState: Bundle?) : if (!device.isNullOrEmpty()) { root.put("device", device) } - val bytes = Json { prettyPrint = true }.printJsonElement(root.build()).toByteArray( + val bytes = kJsonPretty.printJsonElement(root.build()).toByteArray( Charsets.UTF_8 ) out = FileOutputStream(file) @@ -742,7 +742,7 @@ class AccountsPresenter(savedInstanceState: Bundle?) : } } root.put("conversations_saved", arrDialogs.build()) - val bytes = Json { prettyPrint = true }.printJsonElement(root.build()).toByteArray( + val bytes = kJsonPretty.printJsonElement(root.build()).toByteArray( Charsets.UTF_8 ) out = FileOutputStream(file) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/friends/friendsbyphones/FriendsByPhonesPresenter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/friends/friendsbyphones/FriendsByPhonesPresenter.kt index 6f0137054..927217c57 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/friends/friendsbyphones/FriendsByPhonesPresenter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/friends/friendsbyphones/FriendsByPhonesPresenter.kt @@ -10,13 +10,13 @@ import dev.ragnarok.fenrir.domain.IAccountsInteractor import dev.ragnarok.fenrir.domain.InteractorFactory import dev.ragnarok.fenrir.fragment.base.AccountDependencyPresenter import dev.ragnarok.fenrir.kJson +import dev.ragnarok.fenrir.kJsonPretty import dev.ragnarok.fenrir.model.ContactConversation import dev.ragnarok.fenrir.trimmedNonNullNoEmpty import dev.ragnarok.fenrir.util.Utils import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.fromIOToMain -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.decodeFromBufferedSource import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.json.decodeFromBufferedSource import okio.buffer import okio.source import java.io.File @@ -70,11 +70,11 @@ class FriendsByPhonesPresenter(accountId: Long, savedInstanceState: Bundle?) : var out: FileOutputStream? = null try { - val bytes = Json { - prettyPrint = true - }.encodeToString(ListSerializer(ContactConversation.serializer()), data).toByteArray( - Charsets.UTF_8 - ) + val bytes = + kJsonPretty.encodeToString(ListSerializer(ContactConversation.serializer()), data) + .toByteArray( + Charsets.UTF_8 + ) out = FileOutputStream(file) val bom = byteArrayOf(0xEF.toByte(), 0xBB.toByte(), 0xBF.toByte()) out.write(bom) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/messages/dialogs/DialogsFragment.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/messages/dialogs/DialogsFragment.kt index 42104d138..db3f2ba0c 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/messages/dialogs/DialogsFragment.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/messages/dialogs/DialogsFragment.kt @@ -61,6 +61,7 @@ import dev.ragnarok.fenrir.util.HelperSimple.NOTIFICATION_PERMISSION import dev.ragnarok.fenrir.util.HelperSimple.needHelp import dev.ragnarok.fenrir.util.InputTextDialog import dev.ragnarok.fenrir.util.MessagesReplyItemCallback +import dev.ragnarok.fenrir.util.Utils import dev.ragnarok.fenrir.util.ViewUtils.setupSwipeRefreshLayoutWithCurrentTheme import dev.ragnarok.fenrir.util.toast.CustomSnackbars import dev.ragnarok.fenrir.util.toast.CustomToast.Companion.createCustomToast @@ -124,7 +125,7 @@ class DialogsFragment : BaseMvpFragment(), IDial override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) requireActivity().addMenuProvider(this, viewLifecycleOwner) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && needHelp( + if (Utils.hasTiramisuTarget() && needHelp( NOTIFICATION_PERMISSION, 1 ) && !AppPerms.hasNotificationPermissionSimple(requireActivity()) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/requestexecute/RequestExecutePresenter.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/requestexecute/RequestExecutePresenter.kt index 6703b50ce..516d77768 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/requestexecute/RequestExecutePresenter.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/fragment/requestexecute/RequestExecutePresenter.kt @@ -21,11 +21,10 @@ import dev.ragnarok.fenrir.util.Utils.getCauseIfRuntime import dev.ragnarok.fenrir.util.Utils.join import dev.ragnarok.fenrir.util.Utils.safelyClose import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.fromIOToMain -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map -import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import kotlinx.serialization.msgpack.MsgPack import okhttp3.ResponseBody import java.io.File import java.io.FileOutputStream diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/settings/backup/SettingsBackup.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/settings/backup/SettingsBackup.kt index 5eb7e2253..70c4431bc 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/settings/backup/SettingsBackup.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/settings/backup/SettingsBackup.kt @@ -8,13 +8,13 @@ import dev.ragnarok.fenrir.model.ShortcutStored import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.settings.Settings import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.syncSingleSafe -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.JsonObjectBuilder -import dev.ragnarok.fenrir.util.serializeble.prefs.Preferences import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonObjectBuilder +import kotlinx.serialization.prefs.Preferences class SettingsBackup { @Keep diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/DownloadWorkUtils.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/DownloadWorkUtils.kt index 26d9fb584..6ed62cd73 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/DownloadWorkUtils.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/DownloadWorkUtils.kt @@ -44,9 +44,9 @@ import dev.ragnarok.fenrir.toColor import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.inMainThread import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.syncSingleSafe import dev.ragnarok.fenrir.util.hls.M3U8 -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack import dev.ragnarok.fenrir.util.toast.CustomToast import kotlinx.coroutines.flow.map +import kotlinx.serialization.msgpack.MsgPack import okhttp3.Request import java.io.BufferedInputStream import java.io.File diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/OkHttp3LoggingInterceptor.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/OkHttp3LoggingInterceptor.kt index a6d20c592..272fe2293 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/OkHttp3LoggingInterceptor.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/OkHttp3LoggingInterceptor.kt @@ -2,8 +2,8 @@ package dev.ragnarok.fenrir.util import com.github.luben.zstd.ZstdInputStream import dev.ragnarok.fenrir.kJson -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack +import dev.ragnarok.fenrir.kJsonNotPretty +import kotlinx.serialization.msgpack.MsgPack import okhttp3.Headers import okhttp3.Interceptor import okhttp3.Response @@ -265,15 +265,11 @@ class OkHttp3LoggingInterceptor @JvmOverloads constructor( .contains("application/x-msgpack") ) { val pp = MsgPack.parseToJsonElement(buffer.clone()) - logger.log(Json { - prettyPrint = false - }.printJsonElement(pp)) + logger.log(kJsonNotPretty.printJsonElement(pp)) } else if (headers["Content-Type"].orEmpty().lowercase() .contains("application/json") ) { - logger.log(Json { - prettyPrint = false - }.printJsonElement(kJson.parseToJsonElement(buffer.clone()))) + logger.log(kJsonNotPretty.printJsonElement(kJson.parseToJsonElement(buffer.clone()))) } else if (headers["Content-Type"].orEmpty().lowercase() .contains("text/html") ) { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/Utils.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/Utils.kt index 3878429e3..ec5f9279b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/Utils.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/Utils.kt @@ -746,6 +746,10 @@ object Utils { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && BuildConfig.TARGET_SDK >= Build.VERSION_CODES.R } + fun hasTiramisuTarget(): Boolean { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && BuildConfig.TARGET_SDK >= Build.VERSION_CODES.TIRAMISU + } + fun hasVanillaIceCreamTarget(): Boolean { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && BuildConfig.TARGET_SDK >= Build.VERSION_CODES.VANILLA_ICE_CREAM } diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/existfile/FileExistJVM.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/existfile/FileExistJVM.kt index 1c0899c74..598df6ac5 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/existfile/FileExistJVM.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/existfile/FileExistJVM.kt @@ -7,11 +7,11 @@ import dev.ragnarok.fenrir.nonNullNoEmpty import dev.ragnarok.fenrir.settings.Settings import dev.ragnarok.fenrir.util.AppPerms.hasReadStoragePermissionSimple import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.emptyTaskFlow -import dev.ragnarok.fenrir.util.serializeble.json.internal.OkioSerialReader -import dev.ragnarok.fenrir.util.serializeble.json.internal.WriteMode -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.ReaderJsonLexer import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.json.internal.OkioSerialReader +import kotlinx.serialization.json.internal.WriteMode +import kotlinx.serialization.json.internal.lexer.ReaderJsonLexer import okio.buffer import okio.source import java.io.File diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/existfile/FileExistNative.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/existfile/FileExistNative.kt index 97af37bc0..3c1751165 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/existfile/FileExistNative.kt +++ b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/existfile/FileExistNative.kt @@ -8,11 +8,11 @@ import dev.ragnarok.fenrir.module.StringExist import dev.ragnarok.fenrir.settings.Settings import dev.ragnarok.fenrir.util.AppPerms.hasReadStoragePermissionSimple import dev.ragnarok.fenrir.util.coroutines.CoroutinesUtils.emptyTaskFlow -import dev.ragnarok.fenrir.util.serializeble.json.internal.OkioSerialReader -import dev.ragnarok.fenrir.util.serializeble.json.internal.WriteMode -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.ReaderJsonLexer import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.serialization.json.internal.OkioSerialReader +import kotlinx.serialization.json.internal.WriteMode +import kotlinx.serialization.json.internal.lexer.ReaderJsonLexer import okio.buffer import okio.source import java.io.File diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/FormatLanguage.kt b/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/FormatLanguage.kt deleted file mode 100644 index 77930c10a..000000000 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/FormatLanguage.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.ragnarok.fenrir.util.serializeble.json.internal - -import kotlinx.serialization.InternalSerializationApi - -@InternalSerializationApi -@Retention(AnnotationRetention.BINARY) -@Target( - AnnotationTarget.FUNCTION, - AnnotationTarget.PROPERTY_GETTER, - AnnotationTarget.PROPERTY_SETTER, - AnnotationTarget.FIELD, - AnnotationTarget.VALUE_PARAMETER, - AnnotationTarget.LOCAL_VARIABLE, - AnnotationTarget.ANNOTATION_CLASS -) -annotation class FormatLanguage( - val value: String, - // default parameters are not used due to https://youtrack.jetbrains.com/issue/KT-25946/ - val prefix: String, - val suffix: String, -) \ No newline at end of file diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/Json.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/Json.kt similarity index 90% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/Json.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/Json.kt index 150c36e67..10a71c02a 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/Json.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/Json.kt @@ -2,23 +2,23 @@ * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json - -import dev.ragnarok.fenrir.util.serializeble.json.internal.DescriptorSchemaCache -import dev.ragnarok.fenrir.util.serializeble.json.internal.FormatLanguage -import dev.ragnarok.fenrir.util.serializeble.json.internal.JsonToStringWriter -import dev.ragnarok.fenrir.util.serializeble.json.internal.PolymorphismValidator -import dev.ragnarok.fenrir.util.serializeble.json.internal.StreamingJsonDecoder -import dev.ragnarok.fenrir.util.serializeble.json.internal.WriteMode -import dev.ragnarok.fenrir.util.serializeble.json.internal.encodeByWriter -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.StringJsonLexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.readJson -import dev.ragnarok.fenrir.util.serializeble.json.internal.writeJson +package kotlinx.serialization.json + import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.StringFormat +import kotlinx.serialization.json.internal.DescriptorSchemaCache +import kotlinx.serialization.json.internal.FormatLanguage +import kotlinx.serialization.json.internal.JsonSerializersModuleValidator +import kotlinx.serialization.json.internal.JsonToStringWriter +import kotlinx.serialization.json.internal.StreamingJsonDecoder +import kotlinx.serialization.json.internal.WriteMode +import kotlinx.serialization.json.internal.encodeByWriter +import kotlinx.serialization.json.internal.lexer.StringJsonLexer +import kotlinx.serialization.json.internal.readJson +import kotlinx.serialization.json.internal.writeJson import kotlinx.serialization.modules.EmptySerializersModule import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.serializer @@ -132,7 +132,10 @@ sealed class Json( * * @throws [SerializationException] if the given value cannot be serialized to JSON. */ - final override fun encodeToString(serializer: SerializationStrategy, value: T): String { + final override fun encodeToString( + serializer: SerializationStrategy, + value: T + ): String { val result = JsonToStringWriter() try { encodeByWriter(this@Json, result, serializer, value) @@ -142,22 +145,6 @@ sealed class Json( } } - /** - * Decodes and deserializes the given JSON [string] to the value of type [T] using deserializer - * retrieved from the reified type parameter. - * Example: - * ``` - * @Serializable - * data class Project(val name: String, val language: String) - * // Project(name=kotlinx.serialization, language=Kotlin) - * println(Json.decodeFromString("""{"name":"kotlinx.serialization","language":"Kotlin"}""")) - * ``` - * - * @throws SerializationException in case of any decoding-specific error - * @throws IllegalArgumentException if the decoded input is not a valid instance of [T] - */ - inline fun decodeFromString(@FormatLanguage("json", "", "") string: String): T = - decodeFromString(serializersModule.serializer(), string) /** * Deserializes the given JSON [string] into a value of type [T] using the given [deserializer]. @@ -188,7 +175,10 @@ sealed class Json( * * @throws [SerializationException] if the given value cannot be serialized to JSON */ - fun encodeToJsonElement(serializer: SerializationStrategy, value: T): JsonElement { + fun encodeToJsonElement( + serializer: SerializationStrategy, + value: T + ): JsonElement { return writeJson(this@Json, value, serializer) } @@ -221,6 +211,54 @@ sealed class Json( fun printJsonElement(element: JsonElement): String { return encodeToString(JsonElementSerializer, element) } + + /** + * Following functions are copied from extensions on StringFormat + * to streamline experience for newcomers, since IDE does not star-import kotlinx.serialization.* automatically + */ + + /** + * Serializes the [value] of type [T] into an equivalent JSON using serializer + * retrieved from the reified type parameter. + * + * Example of usage: + * ``` + * @Serializable + * class Project(val name: String, val language: String) + * + * val data = Project("kotlinx.serialization", "Kotlin") + * + * // Prints {"name":"kotlinx.serialization","language":"Kotlin"} + * println(Json.encodeToString(data)) + * ``` + * + * @throws [SerializationException] if the given value cannot be serialized to JSON. + */ + inline fun encodeToString(value: T): String = + encodeToString(serializersModule.serializer(), value) + + /** + * Decodes and deserializes the given JSON [string] to the value of type [T] using deserializer + * retrieved from the reified type parameter. + * Example: + * ``` + * @Serializable + * data class Project(val name: String, val language: String) + * // Project(name=kotlinx.serialization, language=Kotlin) + * println(Json.decodeFromString("""{"name":"kotlinx.serialization","language":"Kotlin"}""")) + * ``` + * + * @throws SerializationException in case of any decoding-specific error + * @throws IllegalArgumentException if the decoded input is not a valid instance of [T] + */ + inline fun decodeFromString( + @FormatLanguage( + "json", + "", + "" + ) string: String + ): T = + decodeFromString(serializersModule.serializer(), string) } /** @@ -447,6 +485,11 @@ class JsonBuilder internal constructor(json: Json) { * // Fails with "Encountered an unknown key 'version'" * Json.decodeFromString("""{"name":"unknown", "version": 2.0}""") * ``` + * + * In case you wish to allow unknown properties only for specific class(es), + * consider using [JsonIgnoreUnknownKeys] annotation instead of this configuration flag. + * + * @see JsonIgnoreUnknownKeys */ var ignoreUnknownKeys: Boolean = json.configuration.ignoreUnknownKeys @@ -531,6 +574,13 @@ class JsonBuilder internal constructor(json: Json) { /** * Name of the class descriptor property for polymorphic serialization. * `type` by default. + * + * Note that if your class has any serial names that are equal to [classDiscriminator] + * (e.g., `@Serializable class Foo(val type: String)`), an [IllegalArgumentException] will be thrown from `Json {}` builder. + * You can disable this check and class discriminator inclusion with [ClassDiscriminatorMode.NONE], but kotlinx.serialization will not be + * able to deserialize such data back. + * + * @see classDiscriminatorMode */ var classDiscriminator: String = json.configuration.classDiscriminator @@ -540,9 +590,12 @@ class JsonBuilder internal constructor(json: Json) { * * Other modes are generally intended to produce JSON for consumption by third-party libraries, * therefore, this setting does not affect the deserialization process. + * + * @see classDiscriminator */ @ExperimentalSerializationApi - var classDiscriminatorMode: ClassDiscriminatorMode = json.configuration.classDiscriminatorMode + var classDiscriminatorMode: ClassDiscriminatorMode = + json.configuration.classDiscriminatorMode /** * Specifies whether Json instance makes use of [JsonNames] annotation. @@ -720,10 +773,7 @@ private class JsonImpl(configuration: JsonConfiguration, module: SerializersModu private fun validateConfiguration() { if (serializersModule == EmptySerializersModule()) return // Fast-path for in-place JSON allocations - val collector = PolymorphismValidator( - configuration.useArrayPolymorphism, - configuration.classDiscriminator - ) + val collector = JsonSerializersModuleValidator(configuration) serializersModule.dumpTo(collector) } } diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/JsonAnnotations.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonAnnotations.kt similarity index 69% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/JsonAnnotations.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonAnnotations.kt index f4037a0a1..8bde2c04d 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/JsonAnnotations.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonAnnotations.kt @@ -2,7 +2,7 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json +package kotlinx.serialization.json import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.InheritableSerialInfo @@ -72,3 +72,36 @@ annotation class JsonNames(vararg val names: String) @Target(AnnotationTarget.CLASS) @ExperimentalSerializationApi annotation class JsonClassDiscriminator(val discriminator: String) + + +/** + * Specifies whether encounters of unknown properties (i.e., properties not declared in the class) in the input JSON + * should be ignored instead of throwing [SerializationException]. + * + * With this annotation, it is possible to allow unknown properties for annotated classes, while + * general decoding methods (such as [Json.decodeFromString] and others) would still reject them for everything else. + * If you want [Json.decodeFromString] allow all unknown properties for all classes and inputs, consider using + * [JsonBuilder.ignoreUnknownKeys]. + * + * Example: + * ``` + * @Serializable + * @JsonIgnoreUnknownKeys + * class Outer(val a: Int, val inner: Inner) + * + * @Serializable + * class Inner(val x: String) + * + * // Throws SerializationException because there is no "unknownKey" property in Inner + * Json.decodeFromString("""{"a":1,"inner":{"x":"value","unknownKey":"unknownValue"}}""") + * + * // Decodes successfully despite "unknownKey" property in Outer + * Json.decodeFromString("""{"a":1,"inner":{"x":"value"}, "unknownKey":42}""") + * ``` + * + * @see JsonBuilder.ignoreUnknownKeys + */ +@SerialInfo +@Target(AnnotationTarget.CLASS) +@ExperimentalSerializationApi +annotation class JsonIgnoreUnknownKeys diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonConfiguration.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonConfiguration.kt similarity index 93% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonConfiguration.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonConfiguration.kt index 2c3727715..027a8f4ca 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonConfiguration.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonConfiguration.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json import kotlinx.serialization.ExperimentalSerializationApi @@ -58,8 +58,8 @@ class JsonConfiguration @OptIn(ExperimentalSerializationApi::class) internal con * * @see JsonBuilder.classDiscriminator * @see JsonBuilder.classDiscriminatorMode - * Polymorphic - * PolymorphicSerializer + * @see Polymorphic + * @see PolymorphicSerializer */ enum class ClassDiscriminatorMode { /** @@ -68,6 +68,9 @@ enum class ClassDiscriminatorMode { * This mode is generally intended to produce JSON for consumption by third-party libraries. * kotlinx.serialization is unable to deserialize [polymorphic classes][POLYMORPHIC] without class discriminators, * so it is impossible to deserialize JSON produced in this mode if a data model has polymorphic classes. + * + * Using this mode relaxes several configuration checks in [Json]. In particular, it is possible to serialize enums and primitives + * as polymorphic subclasses in this mode, since it is no longer required for them to have outer `{}` object to include class discriminator. */ NONE, @@ -119,9 +122,9 @@ enum class ClassDiscriminatorMode { * setting [JsonBuilder.classDiscriminatorMode] to [ClassDiscriminatorMode.POLYMORPHIC] adds * class discriminator to `All.b`, but leaves `All.p` and `All.i` intact. * - * SerializersModule - * SerializersModuleBuilder - * PolymorphicModuleBuilder + * @see SerializersModule + * @see SerializersModuleBuilder + * @see PolymorphicModuleBuilder */ POLYMORPHIC, } diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonContentPolymorphicSerializer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonContentPolymorphicSerializer.kt similarity index 99% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonContentPolymorphicSerializer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonContentPolymorphicSerializer.kt index 41de7bbb7..e517bf210 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonContentPolymorphicSerializer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonContentPolymorphicSerializer.kt @@ -2,7 +2,7 @@ * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonDecoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonDecoder.kt similarity index 96% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonDecoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonDecoder.kt index 66d56b46d..c05819977 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonDecoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonDecoder.kt @@ -2,8 +2,9 @@ * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json +import kotlinx.serialization.SealedSerializationApi import kotlinx.serialization.encoding.CompositeDecoder import kotlinx.serialization.encoding.Decoder @@ -50,6 +51,7 @@ import kotlinx.serialization.encoding.Decoder * Accepting this interface in your API methods, casting [Decoder] to [JsonDecoder] and invoking its * methods is considered stable. */ +@SubclassOptInRequired(SealedSerializationApi::class) interface JsonDecoder : Decoder, CompositeDecoder { /** * An instance of the current [Json]. diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonElement.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonElement.kt similarity index 90% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonElement.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonElement.kt index f2fe92455..88c38ca18 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonElement.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonElement.kt @@ -4,19 +4,19 @@ @file:Suppress("unused") -package dev.ragnarok.fenrir.util.serializeble.json - -import dev.ragnarok.fenrir.util.serializeble.json.internal.JsonDecodingException -import dev.ragnarok.fenrir.util.serializeble.json.internal.JsonEncodingException -import dev.ragnarok.fenrir.util.serializeble.json.internal.SuppressAnimalSniffer -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.StringJsonLexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.printQuoted -import dev.ragnarok.fenrir.util.serializeble.json.internal.toBooleanStrictOrNull +package kotlinx.serialization.json + import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.internal.InlinePrimitiveDescriptor +import kotlinx.serialization.json.internal.JsonDecodingException +import kotlinx.serialization.json.internal.JsonEncodingException +import kotlinx.serialization.json.internal.SuppressAnimalSniffer +import kotlinx.serialization.json.internal.lexer.StringJsonLexer +import kotlinx.serialization.json.internal.printQuoted +import kotlinx.serialization.json.internal.toBooleanStrictOrNull /** * Class representing single JSON element. @@ -42,7 +42,7 @@ sealed class JsonPrimitive : JsonElement() { * Indicates whether the primitive was explicitly constructed from [String] and * whether it should be serialized as one. E.g. `JsonPrimitive("42")` is represented * by a string, while `JsonPrimitive(42)` is not. - * These primitives will be serialized as `42` and `"42"` respectively. + * These primitives will be serialized as `"42"` and `42` respectively. */ abstract val isString: Boolean @@ -146,7 +146,7 @@ fun JsonUnquotedLiteral(value: String?): JsonPrimitive { /** Used as a marker to indicate during encoding that the [JsonEncoder] should use `encodeInline()` */ internal val jsonUnquotedLiteralDescriptor: SerialDescriptor = InlinePrimitiveDescriptor( - "dev.ragnarok.fenrir.util.serializeble.json.JsonUnquotedLiteral", + "kotlinx.serialization.json.JsonUnquotedLiteral", String.serializer() ) @@ -271,7 +271,7 @@ val JsonElement.jsonNull: JsonNull */ val JsonPrimitive.int: Int get() { - val result = mapExceptions { StringJsonLexer(content).consumeNumericLiteral() } + val result = exceptionToNumberFormatException { parseLongImpl() } if (result !in Int.MIN_VALUE..Int.MAX_VALUE) throw NumberFormatException("$content is not an Int") return result.toInt() } @@ -281,8 +281,7 @@ val JsonPrimitive.int: Int */ val JsonPrimitive.intOrNull: Int? get() { - val result = - mapExceptionsToNull { StringJsonLexer(content).consumeNumericLiteral() } ?: return null + val result = exceptionToNull { parseLongImpl() } ?: return null if (result !in Int.MIN_VALUE..Int.MAX_VALUE) return null return result.toInt() } @@ -291,14 +290,13 @@ val JsonPrimitive.intOrNull: Int? * Returns content of current element as long * @throws NumberFormatException if current element is not a valid representation of number */ -val JsonPrimitive.long: Long get() = mapExceptions { StringJsonLexer(content).consumeNumericLiteral() } +val JsonPrimitive.long: Long get() = exceptionToNumberFormatException { parseLongImpl() } /** * Returns content of current element as long or `null` if current element is not a valid representation of number */ val JsonPrimitive.longOrNull: Long? - get() = - mapExceptionsToNull { StringJsonLexer(content).consumeNumericLiteral() } + get() = exceptionToNull { parseLongImpl() } /** * Returns content of current element as double @@ -343,7 +341,7 @@ val JsonPrimitive.contentOrNull: String? get() = if (this is JsonNull) null else private fun JsonElement.error(element: String): Nothing = throw IllegalArgumentException("Element ${this::class} is not a $element") -private inline fun mapExceptionsToNull(f: () -> T): T? { +private inline fun exceptionToNull(f: () -> T): T? { return try { f() } catch (e: JsonDecodingException) { @@ -351,7 +349,7 @@ private inline fun mapExceptionsToNull(f: () -> T): T? { } } -private inline fun mapExceptions(f: () -> T): T { +private inline fun exceptionToNumberFormatException(f: () -> T): T { return try { f() } catch (e: JsonDecodingException) { @@ -362,3 +360,7 @@ private inline fun mapExceptions(f: () -> T): T { @PublishedApi internal fun unexpectedJson(key: String, expected: String): Nothing = throw IllegalArgumentException("Element $key is not a $expected") + +// Use this function to avoid re-wrapping exception into NumberFormatException +internal fun JsonPrimitive.parseLongImpl(): Long = + StringJsonLexer(content).consumeNumericLiteralFully() diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonElementBuilders.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonElementBuilders.kt similarity index 99% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonElementBuilders.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonElementBuilders.kt index cec050c93..7e6c1643a 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonElementBuilders.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonElementBuilders.kt @@ -3,7 +3,7 @@ */ @file:OptIn(ExperimentalContracts::class) -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json import kotlinx.serialization.ExperimentalSerializationApi import kotlin.contracts.ExperimentalContracts diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonElementSerializers.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonElementSerializers.kt similarity index 94% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonElementSerializers.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonElementSerializers.kt index a63cfffe3..95fad3fbc 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonElementSerializers.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonElementSerializers.kt @@ -3,9 +3,8 @@ */ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json -import dev.ragnarok.fenrir.util.serializeble.json.internal.JsonDecodingException import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.ListSerializer @@ -19,6 +18,7 @@ import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.buildSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.internal.JsonDecodingException /** * Serializer object providing [SerializationStrategy] and [DeserializationStrategy] for [JsonElement]. @@ -36,7 +36,7 @@ import kotlinx.serialization.encoding.Encoder internal object JsonElementSerializer : KSerializer { override val descriptor: SerialDescriptor = buildSerialDescriptor( - "dev.ragnarok.fenrir.util.serializeble.json.JsonElement", + "kotlinx.serialization.json.JsonElement", PolymorphicKind.SEALED ) { // Resolve cyclic dependency in descriptors by late binding @@ -70,7 +70,7 @@ internal object JsonElementSerializer : KSerializer { internal object JsonPrimitiveSerializer : KSerializer { override val descriptor: SerialDescriptor = buildSerialDescriptor( - "dev.ragnarok.fenrir.util.serializeble.json.JsonPrimitive", + "kotlinx.serialization.json.JsonPrimitive", PrimitiveKind.STRING ) @@ -103,7 +103,7 @@ internal object JsonNullSerializer : KSerializer { // technically, JsonNull is an object, but it does not call beginStructure/endStructure at all override val descriptor: SerialDescriptor = buildSerialDescriptor( - "dev.ragnarok.fenrir.util.serializeble.json.JsonNull", + "kotlinx.serialization.json.JsonNull", SerialKind.ENUM ) @@ -126,7 +126,7 @@ private object JsonLiteralSerializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( - "dev.ragnarok.fenrir.util.serializeble.json.JsonLiteral", + "kotlinx.serialization.json.JsonLiteral", PrimitiveKind.STRING ) @@ -177,7 +177,7 @@ internal object JsonObjectSerializer : KSerializer { private object JsonObjectDescriptor : SerialDescriptor by MapSerializer(String.serializer(), JsonElementSerializer).descriptor { @ExperimentalSerializationApi - override val serialName: String = "dev.ragnarok.fenrir.util.serializeble.json.JsonObject" + override val serialName: String = "kotlinx.serialization.json.JsonObject" } override val descriptor: SerialDescriptor = JsonObjectDescriptor @@ -207,7 +207,7 @@ internal object JsonArraySerializer : KSerializer { private object JsonArrayDescriptor : SerialDescriptor by ListSerializer(JsonElementSerializer).descriptor { @ExperimentalSerializationApi - override val serialName: String = "dev.ragnarok.fenrir.util.serializeble.json.JsonArray" + override val serialName: String = "kotlinx.serialization.json.JsonArray" } override val descriptor: SerialDescriptor = JsonArrayDescriptor diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonEncoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonEncoder.kt similarity index 96% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonEncoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonEncoder.kt index a01ab220e..40a1d44b8 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonEncoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonEncoder.kt @@ -2,8 +2,9 @@ * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json +import kotlinx.serialization.SealedSerializationApi import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.encoding.Encoder @@ -50,6 +51,7 @@ import kotlinx.serialization.encoding.Encoder * Accepting this interface in your API methods, casting [Encoder] to [JsonEncoder] and invoking its * methods is considered stable. */ +@SubclassOptInRequired(SealedSerializationApi::class) interface JsonEncoder : Encoder, CompositeEncoder { /** * An instance of the current [Json]. diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonNamingStrategy.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonNamingStrategy.kt similarity index 97% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonNamingStrategy.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonNamingStrategy.kt index 28d9699aa..313e43354 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonNamingStrategy.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonNamingStrategy.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.SerialDescriptor @@ -106,7 +106,7 @@ fun interface JsonNamingStrategy { ): String = convertCamelCase(serialName, '_') override fun toString(): String = - "dev.ragnarok.fenrir.util.serializeble.json.JsonNamingStrategy.SnakeCase" + "kotlinx.serialization.json.JsonNamingStrategy.SnakeCase" } /** @@ -142,7 +142,7 @@ fun interface JsonNamingStrategy { ): String = convertCamelCase(serialName, '-') override fun toString(): String = - "dev.ragnarok.fenrir.util.serializeble.json.JsonNamingStrategy.KebabCase" + "kotlinx.serialization.json.JsonNamingStrategy.KebabCase" } private fun convertCamelCase( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonSchemaCache.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonSchemaCache.kt similarity index 63% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonSchemaCache.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonSchemaCache.kt index 73b699aec..230e0677f 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonSchemaCache.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonSchemaCache.kt @@ -2,9 +2,9 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json -import dev.ragnarok.fenrir.util.serializeble.json.internal.DescriptorSchemaCache +import kotlinx.serialization.json.internal.DescriptorSchemaCache @Suppress("DEPRECATION_ERROR") internal val Json.schemaCache: DescriptorSchemaCache diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonTransformingSerializer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonTransformingSerializer.kt similarity index 97% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonTransformingSerializer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonTransformingSerializer.kt index 91bc62b9f..742514822 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/JsonTransformingSerializer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/JsonTransformingSerializer.kt @@ -2,13 +2,13 @@ * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json -import dev.ragnarok.fenrir.util.serializeble.json.internal.writeJson import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.internal.writeJson /** * Base class for custom serializers that allows manipulating an abstract JSON diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/OkioStreams.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/OkioStreams.kt similarity index 91% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/OkioStreams.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/OkioStreams.kt index e0eec963c..61c73ed44 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/OkioStreams.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/OkioStreams.kt @@ -2,16 +2,16 @@ * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json +package kotlinx.serialization.json -import dev.ragnarok.fenrir.util.serializeble.json.internal.JsonToOkioStreamWriter -import dev.ragnarok.fenrir.util.serializeble.json.internal.OkioSerialReader -import dev.ragnarok.fenrir.util.serializeble.json.internal.decodeByReader -import dev.ragnarok.fenrir.util.serializeble.json.internal.decodeToSequenceByReader -import dev.ragnarok.fenrir.util.serializeble.json.internal.encodeByWriter import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.json.internal.JsonToOkioStreamWriter +import kotlinx.serialization.json.internal.OkioSerialReader +import kotlinx.serialization.json.internal.decodeByReader +import kotlinx.serialization.json.internal.decodeToSequenceByReader +import kotlinx.serialization.json.internal.encodeByWriter import kotlinx.serialization.serializer import okio.BufferedSink import okio.BufferedSource diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/ArrayPools.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/ArrayPools.kt similarity index 92% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/ArrayPools.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/ArrayPools.kt index 2c8462a59..6e7ce641f 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/ArrayPools.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/ArrayPools.kt @@ -1,16 +1,16 @@ /* * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.BATCH_SIZE +import kotlinx.serialization.json.internal.lexer.BATCH_SIZE /* * Not really documented kill switch as a workaround for potential * (unlikely) problems with memory consumptions. */ private val MAX_CHARS_IN_POOL = runCatching { - System.getProperty("dev.ragnarok.fenrir.util.serializeble.json.pool.size")?.toIntOrNull() + System.getProperty("kotlinx.serialization.json.pool.size")?.toIntOrNull() }.getOrNull() ?: (2 * 1024 * 1024) internal open class CharArrayPoolBase { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/Composers.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/Composers.kt similarity index 96% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/Composers.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/Composers.kt index c995b7bf2..4b8236e7b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/Composers.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/Composers.kt @@ -4,10 +4,10 @@ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.Json import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.Json internal fun Composer(sb: InternalJsonWriter, json: Json): Composer = if (json.configuration.prettyPrint) ComposerWithPrettyPrint(sb, json) else Composer(sb) diff --git a/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/FormatLanguage.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/FormatLanguage.kt new file mode 100644 index 000000000..ccce10183 --- /dev/null +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/FormatLanguage.kt @@ -0,0 +1,45 @@ +package kotlinx.serialization.json.internal + +import kotlinx.serialization.InternalSerializationApi + +/** + * Multiplatform analogue of `org.intellij.lang.annotations.Language` annotation. + * + * An alias is used instead of class, because the actual class in the JVM will conflict with the class from the stdlib - + * we want to avoid the situation with different classes having the same fully qualified name. + * [see](https://github.com/JetBrains/java-annotations/issues/34) + * + * Specifies that an element of the program represents a string that is a source code on a specified language. + * Code editors may use this annotation to enable syntax highlighting, code completion and other features + * inside the literals that assigned to the annotated variables, passed as arguments to the annotated parameters, + * or returned from the annotated methods. + *

+ * This annotation also could be used as a meta-annotation, to define derived annotations for convenience. + * E.g. the following annotation could be defined to annotate the strings that represent Java methods: + * + *

+ *   @Language(value = "JAVA", prefix = "class X{", suffix = "}")
+ *   @interface JavaMethod {}
+ * 
+ *

+ * Note that using the derived annotation as meta-annotation is not supported. + * Meta-annotation works only one level deep. + */ + +@InternalSerializationApi +@Retention(AnnotationRetention.BINARY) +@Target( + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY_GETTER, + AnnotationTarget.PROPERTY_SETTER, + AnnotationTarget.FIELD, + AnnotationTarget.VALUE_PARAMETER, + AnnotationTarget.LOCAL_VARIABLE, + AnnotationTarget.ANNOTATION_CLASS +) +annotation class FormatLanguage( + val value: String, + // default parameters are not used due to https://youtrack.jetbrains.com/issue/KT-25946/ + val prefix: String, + val suffix: String, +) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonElementMarker.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonElementMarker.kt similarity index 94% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonElementMarker.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonElementMarker.kt index 059864217..c5075dc21 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonElementMarker.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonElementMarker.kt @@ -3,7 +3,7 @@ */ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.SerialDescriptor diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonExceptions.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonExceptions.kt similarity index 86% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonExceptions.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonExceptions.kt index db140e94e..46b5113e3 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonExceptions.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonExceptions.kt @@ -4,15 +4,14 @@ @file:Suppress("FunctionName") -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.AbstractJsonLexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.allowStructuredMapKeysHint -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.ignoreUnknownKeysHint -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.specialFlowingValuesHint import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.json.internal.lexer.AbstractJsonLexer +import kotlinx.serialization.json.internal.lexer.allowStructuredMapKeysHint +import kotlinx.serialization.json.internal.lexer.specialFlowingValuesHint /** * Generic exception indicating a problem with JSON serialization and deserialization. @@ -82,13 +81,6 @@ private fun unexpectedFpErrorMessage(value: Number, key: String, output: String) "Current output: ${output.minify()}" } -internal fun UnknownKeyException(key: String, input: String) = JsonDecodingException( - -1, - "Encountered an unknown key '$key'.\n" + - "$ignoreUnknownKeysHint\n" + - "Current input: ${input.minify()}" -) - internal fun CharSequence.minify(offset: Int = -1): CharSequence { if (length < 200) return this if (offset == -1) { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonIterator.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonIterator.kt similarity index 86% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonIterator.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonIterator.kt index 657310d68..bc954d383 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonIterator.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonIterator.kt @@ -5,17 +5,17 @@ @file:Suppress("FunctionName") @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.DecodeSequenceMode -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.AbstractJsonLexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.COMMA -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.ReaderJsonLexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_BEGIN_LIST -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_END_LIST import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.DecodeSequenceMode +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.internal.lexer.AbstractJsonLexer +import kotlinx.serialization.json.internal.lexer.COMMA +import kotlinx.serialization.json.internal.lexer.ReaderJsonLexer +import kotlinx.serialization.json.internal.lexer.TC_BEGIN_LIST +import kotlinx.serialization.json.internal.lexer.TC_END_LIST internal fun JsonIterator( mode: DecodeSequenceMode, diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonNamesMap.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonNamesMap.kt similarity index 94% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonNamesMap.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonNamesMap.kt index 9f366bf57..7e62660fc 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonNamesMap.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonNamesMap.kt @@ -3,18 +3,19 @@ */ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.JsonNames -import dev.ragnarok.filegallery.util.serializeble.json.JsonNamingStrategy -import dev.ragnarok.filegallery.util.serializeble.json.schemaCache import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.encoding.CompositeDecoder +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonIgnoreUnknownKeys +import kotlinx.serialization.json.JsonNames +import kotlinx.serialization.json.JsonNamingStrategy +import kotlinx.serialization.json.schemaCache internal val JsonDeserializationNamesKey = DescriptorSchemaCache.Key>() @@ -173,3 +174,6 @@ internal inline fun Json.tryCoerceValue( } return false } + +internal fun SerialDescriptor.ignoreUnknownKeys(json: Json): Boolean = + json.configuration.ignoreUnknownKeys || annotations.any { it is JsonIgnoreUnknownKeys } diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonPath.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonPath.kt similarity index 98% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonPath.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonPath.kt index ead909e58..80e603eea 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonPath.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonPath.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.SerialDescriptor diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/PolymorphismValidator.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonSerializersModuleValidator.kt similarity index 85% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/PolymorphismValidator.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonSerializersModuleValidator.kt index 831c6c065..5bed29dcc 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/PolymorphismValidator.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonSerializersModuleValidator.kt @@ -2,7 +2,7 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi @@ -13,15 +13,21 @@ import kotlinx.serialization.descriptors.PrimitiveKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.StructureKind +import kotlinx.serialization.json.ClassDiscriminatorMode +import kotlinx.serialization.json.JsonConfiguration import kotlinx.serialization.modules.SerializersModuleCollector import kotlin.reflect.KClass @OptIn(ExperimentalSerializationApi::class) -internal class PolymorphismValidator( - private val useArrayPolymorphism: Boolean, - private val discriminator: String +internal class JsonSerializersModuleValidator( + configuration: JsonConfiguration, ) : SerializersModuleCollector { + private val discriminator: String = configuration.classDiscriminator + private val useArrayPolymorphism: Boolean = configuration.useArrayPolymorphism + private val isDiscriminatorRequired = + configuration.classDiscriminatorMode != ClassDiscriminatorMode.NONE + override fun contextual( kClass: KClass, provider: (typeArgumentsSerializers: List>) -> KSerializer<*> @@ -36,7 +42,7 @@ internal class PolymorphismValidator( ) { val descriptor = actualSerializer.descriptor checkKind(descriptor, actualClass) - if (!useArrayPolymorphism) { + if (!useArrayPolymorphism && isDiscriminatorRequired) { // Collisions with "type" can happen only for JSON polymorphism checkDiscriminatorCollisions(descriptor, actualClass) } @@ -52,6 +58,7 @@ internal class PolymorphismValidator( } if (useArrayPolymorphism) return + if (!isDiscriminatorRequired) return /* * For this kind we can't intercept the JSON object {} in order to add "type: ...". * Except for maps that just can clash and accidentally overwrite the type. diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonStreams.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonStreams.kt similarity index 93% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonStreams.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonStreams.kt index 05ff4f87d..311939b44 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonStreams.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonStreams.kt @@ -1,12 +1,12 @@ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.DecodeSequenceMode -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.BATCH_SIZE -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.ReaderJsonLexer import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.json.DecodeSequenceMode +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.internal.lexer.BATCH_SIZE +import kotlinx.serialization.json.internal.lexer.ReaderJsonLexer import kotlinx.serialization.serializer internal annotation class JsonFriendModuleApi diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonToStringWriter.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonToStringWriter.kt similarity index 98% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonToStringWriter.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonToStringWriter.kt index 4e07e757c..e612df531 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonToStringWriter.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonToStringWriter.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal /** * Optimized version of StringBuilder that is specific to JSON-encoding. diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonTreeReader.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonTreeReader.kt similarity index 78% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonTreeReader.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonTreeReader.kt index 30066811e..92fa6bb92 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonTreeReader.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/JsonTreeReader.kt @@ -2,27 +2,27 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.JsonArray -import dev.ragnarok.fenrir.util.serializeble.json.JsonConfiguration -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonLiteral -import dev.ragnarok.fenrir.util.serializeble.json.JsonNull -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.JsonPrimitive -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.AbstractJsonLexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.NULL -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_BEGIN_LIST -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_BEGIN_OBJ -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_COLON -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_COMMA -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_END_LIST -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_END_OBJ -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_OTHER -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_STRING -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.tokenDescription import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonConfiguration +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonLiteral +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.internal.lexer.AbstractJsonLexer +import kotlinx.serialization.json.internal.lexer.NULL +import kotlinx.serialization.json.internal.lexer.TC_BEGIN_LIST +import kotlinx.serialization.json.internal.lexer.TC_BEGIN_OBJ +import kotlinx.serialization.json.internal.lexer.TC_COLON +import kotlinx.serialization.json.internal.lexer.TC_COMMA +import kotlinx.serialization.json.internal.lexer.TC_END_LIST +import kotlinx.serialization.json.internal.lexer.TC_END_OBJ +import kotlinx.serialization.json.internal.lexer.TC_OTHER +import kotlinx.serialization.json.internal.lexer.TC_STRING +import kotlinx.serialization.json.internal.lexer.tokenDescription @OptIn(ExperimentalSerializationApi::class) internal class JsonTreeReader( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/OkioJsonStreams.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/OkioJsonStreams.kt similarity index 95% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/OkioJsonStreams.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/OkioJsonStreams.kt index c950a8721..9e9006c4b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/OkioJsonStreams.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/OkioJsonStreams.kt @@ -2,7 +2,7 @@ * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal import okio.BufferedSink import okio.BufferedSource diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/Polymorphic.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/Polymorphic.kt similarity index 87% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/Polymorphic.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/Polymorphic.kt index d8389b83e..d73138b20 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/Polymorphic.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/Polymorphic.kt @@ -3,17 +3,8 @@ */ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.ClassDiscriminatorMode -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.JsonClassDiscriminator -import dev.ragnarok.fenrir.util.serializeble.json.JsonDecoder -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonEncoder -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.contentOrNull -import dev.ragnarok.fenrir.util.serializeble.json.jsonPrimitive import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SealedClassSerializer @@ -27,6 +18,15 @@ import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.findPolymorphicSerializer import kotlinx.serialization.internal.AbstractPolymorphicSerializer import kotlinx.serialization.internal.jsonCachedSerialNames +import kotlinx.serialization.json.ClassDiscriminatorMode +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonClassDiscriminator +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonEncoder +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.contentOrNull +import kotlinx.serialization.json.jsonPrimitive @Suppress("UNCHECKED_CAST") internal inline fun JsonEncoder.encodePolymorphically( @@ -54,12 +54,10 @@ internal inline fun JsonEncoder.encodePolymorphically( val casted = serializer as AbstractPolymorphicSerializer requireNotNull(value) { "Value for serializer ${serializer.descriptor} should always be non-null. Please report issue to the kotlinx.serialization tracker." } val actual = casted.findPolymorphicSerializer(this, value) - if (baseClassDiscriminator != null) validateIfSealed( - serializer, - actual, - baseClassDiscriminator - ) - checkKind(actual.descriptor.kind) + if (baseClassDiscriminator != null) { + validateIfSealed(serializer, actual, baseClassDiscriminator) + checkKind(actual.descriptor.kind) + } actual as SerializationStrategy } else serializer diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/SchemaCache.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/SchemaCache.kt similarity index 90% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/SchemaCache.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/SchemaCache.kt index 8331def6e..76ff08e63 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/SchemaCache.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/SchemaCache.kt @@ -2,7 +2,7 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal import kotlinx.serialization.descriptors.SerialDescriptor @@ -24,7 +24,11 @@ internal class DescriptorSchemaCache { map.getOrPut(descriptor) { createMapForCache(2) }[key as Key] = value as Any } - fun getOrPut(descriptor: SerialDescriptor, key: Key, defaultValue: () -> T): T { + fun getOrPut( + descriptor: SerialDescriptor, + key: Key, + defaultValue: () -> T + ): T { get(descriptor, key)?.let { return it } val value = defaultValue() set(descriptor, key, value) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/StreamingJsonDecoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt similarity index 94% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/StreamingJsonDecoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt index 56016c961..473820b9a 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/StreamingJsonDecoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt @@ -2,15 +2,8 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal - -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.JsonDecoder -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.AbstractJsonLexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.COLON -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.StringJsonLexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.TC_COMMA +package kotlinx.serialization.json.internal + import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.MissingFieldException @@ -24,6 +17,13 @@ import kotlinx.serialization.encoding.CompositeDecoder.Companion.UNKNOWN_NAME import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.findPolymorphicSerializer import kotlinx.serialization.internal.AbstractPolymorphicSerializer +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.internal.lexer.AbstractJsonLexer +import kotlinx.serialization.json.internal.lexer.COLON +import kotlinx.serialization.json.internal.lexer.StringJsonLexer +import kotlinx.serialization.json.internal.lexer.TC_COMMA import kotlinx.serialization.modules.SerializersModule /** @@ -138,7 +138,7 @@ internal open class StreamingJsonDecoder( // If we're ignoring unknown keys, we have to skip all un-decoded elements, // e.g. for object serialization. It can be the case when the descriptor does // not have any elements and decodeElementIndex is not invoked at all - if (json.configuration.ignoreUnknownKeys && descriptor.elementsCount == 0) { + if (descriptor.elementsCount == 0 && descriptor.ignoreUnknownKeys(json)) { skipLeftoverElements(descriptor) } if (lexer.tryConsumeComma() && !json.configuration.allowTrailingComma) lexer.invalidTrailingComma( @@ -259,7 +259,7 @@ internal open class StreamingJsonDecoder( } if (isUnknown) { // slow-path for unknown keys handling - hasComma = handleUnknown(key) + hasComma = handleUnknown(descriptor, key) } } if (hasComma && !json.configuration.allowTrailingComma) lexer.invalidTrailingComma() @@ -267,12 +267,13 @@ internal open class StreamingJsonDecoder( return elementMarker?.nextUnmarkedIndex() ?: DECODE_DONE } - private fun handleUnknown(key: String): Boolean { - if (configuration.ignoreUnknownKeys || discriminatorHolder.trySkip(key)) { + private fun handleUnknown(descriptor: SerialDescriptor, key: String): Boolean { + if (descriptor.ignoreUnknownKeys(json) || discriminatorHolder.trySkip(key)) { lexer.skipElement(configuration.isLenient) } else { - // Here we cannot properly update json path indices - // as we do not have a proper SerialDescriptor in our hands + // Since path is updated on key decoding, it ends with the key that was successfully decoded last, + // and we need to remove it to correctly point to the outer structure. + lexer.path.popDescriptor() lexer.failOnUnknownKey(key) } return lexer.tryConsumeComma() diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/StreamingJsonEncoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt similarity index 92% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/StreamingJsonEncoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt index d428a4dce..4555cd3b7 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/StreamingJsonEncoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt @@ -2,18 +2,8 @@ * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal - -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonElementSerializer -import dev.ragnarok.fenrir.util.serializeble.json.JsonEncoder -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.COLON -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.COMMA -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.INVALID -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.NULL -import dev.ragnarok.fenrir.util.serializeble.json.jsonUnquotedLiteralDescriptor +package kotlinx.serialization.json.internal + import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.builtins.serializer @@ -21,6 +11,16 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.AbstractEncoder import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonElementSerializer +import kotlinx.serialization.json.JsonEncoder +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.internal.lexer.COLON +import kotlinx.serialization.json.internal.lexer.COMMA +import kotlinx.serialization.json.internal.lexer.INVALID +import kotlinx.serialization.json.internal.lexer.NULL +import kotlinx.serialization.json.jsonUnquotedLiteralDescriptor import kotlinx.serialization.modules.SerializersModule private val unsignedNumberDescriptors = setOf( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/StringOps.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/StringOps.kt similarity index 89% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/StringOps.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/StringOps.kt index 22e808d44..e929c4433 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/StringOps.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/StringOps.kt @@ -2,9 +2,9 @@ * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.STRING +import kotlinx.serialization.json.internal.lexer.STRING private fun toHexChar(i: Int): Char { val d = i and 0xf @@ -12,8 +12,8 @@ private fun toHexChar(i: Int): Char { else (d - 10 + 'a'.code).toChar() } -@PublishedApi -internal val ESCAPE_STRINGS: Array = arrayOfNulls(93).apply { +@JsonFriendModuleApi +val ESCAPE_STRINGS: Array = arrayOfNulls(93).apply { for (c in 0..0x1f) { val c1 = toHexChar(c shr 12) val c2 = toHexChar(c shr 8) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/SuppressAnimalSniffer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/SuppressAnimalSniffer.kt similarity index 88% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/SuppressAnimalSniffer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/SuppressAnimalSniffer.kt index 4dd97fd44..1ca90e71b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/SuppressAnimalSniffer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/SuppressAnimalSniffer.kt @@ -2,7 +2,7 @@ * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal /** * Suppresses Animal Sniffer plugin errors for certain methods. diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/TreeJsonDecoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonDecoder.kt similarity index 89% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/TreeJsonDecoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonDecoder.kt index 4d378b7b8..087691cd5 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/TreeJsonDecoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonDecoder.kt @@ -5,25 +5,8 @@ @file:Suppress("LeakingThis") @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.filegallery.util.serializeble.json.internal - -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.JsonArray -import dev.ragnarok.filegallery.util.serializeble.json.JsonDecoder -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.json.JsonLiteral -import dev.ragnarok.filegallery.util.serializeble.json.JsonNull -import dev.ragnarok.filegallery.util.serializeble.json.JsonObject -import dev.ragnarok.filegallery.util.serializeble.json.JsonPrimitive -import dev.ragnarok.filegallery.util.serializeble.json.booleanOrNull -import dev.ragnarok.filegallery.util.serializeble.json.contentOrNull -import dev.ragnarok.filegallery.util.serializeble.json.double -import dev.ragnarok.filegallery.util.serializeble.json.float -import dev.ragnarok.filegallery.util.serializeble.json.int -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.StringJsonLexer -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.lenientHint -import dev.ragnarok.filegallery.util.serializeble.json.long -import dev.ragnarok.filegallery.util.serializeble.json.schemaCache +package kotlinx.serialization.json.internal + import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.PolymorphicKind @@ -33,10 +16,31 @@ import kotlinx.serialization.encoding.CompositeDecoder import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.internal.NamedValueDecoder import kotlinx.serialization.internal.jsonCachedSerialNames +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonLiteral +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.booleanOrNull +import kotlinx.serialization.json.contentOrNull +import kotlinx.serialization.json.double +import kotlinx.serialization.json.float +import kotlinx.serialization.json.internal.lexer.StringJsonLexer +import kotlinx.serialization.json.internal.lexer.ignoreUnknownKeysHint +import kotlinx.serialization.json.internal.lexer.lenientHint +import kotlinx.serialization.json.parseLongImpl +import kotlinx.serialization.json.schemaCache import kotlinx.serialization.modules.SerializersModule @JsonFriendModuleApi -fun readJson(json: Json, element: JsonElement, deserializer: DeserializationStrategy): T { +fun readJson( + json: Json, + element: JsonElement, + deserializer: DeserializationStrategy +): T { val input = when (element) { is JsonObject -> JsonTreeDecoder(json, element) is JsonArray -> JsonTreeListDecoder(json, element) @@ -158,19 +162,24 @@ private sealed class AbstractJsonTreeDecoder( getPrimitiveValue(tag, "boolean", JsonPrimitive::booleanOrNull) override fun decodeTaggedByte(tag: String) = getPrimitiveValue(tag, "byte") { - val result = int + val result = parseLongImpl() if (result in Byte.MIN_VALUE..Byte.MAX_VALUE) result.toByte() else null } override fun decodeTaggedShort(tag: String) = getPrimitiveValue(tag, "short") { - val result = int + val result = parseLongImpl() if (result in Short.MIN_VALUE..Short.MAX_VALUE) result.toShort() else null } - override fun decodeTaggedInt(tag: String) = getPrimitiveValue(tag, "int") { int } - override fun decodeTaggedLong(tag: String) = getPrimitiveValue(tag, "long") { long } + override fun decodeTaggedInt(tag: String) = getPrimitiveValue(tag, "int") { + val result = parseLongImpl() + if (result in Int.MIN_VALUE..Int.MAX_VALUE) result.toInt() + else null + } + + override fun decodeTaggedLong(tag: String) = getPrimitiveValue(tag, "long") { parseLongImpl() } override fun decodeTaggedFloat(tag: String): Float { val result = getPrimitiveValue(tag, "float") { float } @@ -326,7 +335,7 @@ private open class JsonTreeDecoder( } override fun endStructure(descriptor: SerialDescriptor) { - if (configuration.ignoreUnknownKeys || descriptor.kind is PolymorphicKind) return + if (descriptor.ignoreUnknownKeys(json) || descriptor.kind is PolymorphicKind) return // Validate keys val strategy = descriptor.namingStrategy(json) @@ -339,7 +348,12 @@ private open class JsonTreeDecoder( for (key in value.keys) { if (key !in names && key != polymorphicDiscriminator) { - throw UnknownKeyException(key, value.toString()) + throw JsonDecodingException( + -1, + "Encountered an unknown key '$key' at element: ${renderTagStack()}\n" + + "$ignoreUnknownKeysHint\n" + + "JSON input: ${value.toString().minify()}" + ) } } } diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/TreeJsonEncoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonEncoder.kt similarity index 93% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/TreeJsonEncoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonEncoder.kt index 0de3c759e..70ae22335 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/TreeJsonEncoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonEncoder.kt @@ -3,21 +3,9 @@ */ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.fenrir.util.serializeble.json.internal - -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.JsonArray -import dev.ragnarok.fenrir.util.serializeble.json.JsonArraySerializer -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonElementSerializer -import dev.ragnarok.fenrir.util.serializeble.json.JsonEncoder -import dev.ragnarok.fenrir.util.serializeble.json.JsonLiteral -import dev.ragnarok.fenrir.util.serializeble.json.JsonNull -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.JsonObjectSerializer -import dev.ragnarok.fenrir.util.serializeble.json.JsonPrimitive +package kotlinx.serialization.json.internal + import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.PrimitiveKind @@ -28,6 +16,17 @@ import kotlinx.serialization.encoding.AbstractEncoder import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.internal.NamedValueEncoder +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonArraySerializer +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonElementSerializer +import kotlinx.serialization.json.JsonEncoder +import kotlinx.serialization.json.JsonLiteral +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonObjectSerializer +import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.modules.SerializersModule import kotlin.collections.set @@ -39,8 +38,6 @@ fun writeJson(json: Json, value: T, serializer: SerializationStrategy): J return result } -@OptIn(InternalSerializationApi::class) -@ExperimentalSerializationApi private sealed class AbstractJsonTreeEncoder( final override val json: Json, val nodeConsumer: (JsonElement) -> Unit diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/WriteMode.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/WriteMode.kt similarity index 83% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/WriteMode.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/WriteMode.kt index 27e1bb890..66563e18b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/WriteMode.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/WriteMode.kt @@ -3,13 +3,8 @@ */ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.BEGIN_LIST -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.BEGIN_OBJ -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.END_LIST -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.END_OBJ import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.PrimitiveKind @@ -17,6 +12,11 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.descriptors.getContextualDescriptor +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.internal.lexer.BEGIN_LIST +import kotlinx.serialization.json.internal.lexer.BEGIN_OBJ +import kotlinx.serialization.json.internal.lexer.END_LIST +import kotlinx.serialization.json.internal.lexer.END_OBJ import kotlinx.serialization.modules.SerializersModule internal enum class WriteMode(@JvmField val begin: Char, @JvmField val end: Char) { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/createMapForCache.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/createMapForCache.kt similarity index 88% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/createMapForCache.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/createMapForCache.kt index 5bb6609f4..28544bd05 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/createMapForCache.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/createMapForCache.kt @@ -2,7 +2,7 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal import java.util.concurrent.ConcurrentHashMap diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/AbstractJsonLexer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/AbstractJsonLexer.kt similarity index 95% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/AbstractJsonLexer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/AbstractJsonLexer.kt index e15b91b12..297252fc9 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/AbstractJsonLexer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/AbstractJsonLexer.kt @@ -2,12 +2,13 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal.lexer +package kotlinx.serialization.json.internal.lexer -import dev.ragnarok.filegallery.util.serializeble.json.internal.JsonDecodingException -import dev.ragnarok.filegallery.util.serializeble.json.internal.JsonPath -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.CharMappings.CHAR_TO_TOKEN -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.CharMappings.ESCAPE_2_CHAR +import kotlinx.serialization.json.internal.JsonDecodingException +import kotlinx.serialization.json.internal.JsonPath +import kotlinx.serialization.json.internal.lexer.CharMappings.CHAR_TO_TOKEN +import kotlinx.serialization.json.internal.lexer.CharMappings.ESCAPE_2_CHAR +import kotlinx.serialization.json.internal.minify import kotlin.math.floor import kotlin.math.pow @@ -18,7 +19,7 @@ internal const val coerceInputValuesHint = internal const val specialFlowingValuesHint = "It is possible to deserialize them using 'JsonBuilder.allowSpecialFloatingPointValues = true'" internal const val ignoreUnknownKeysHint = - "Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys." + "Use 'ignoreUnknownKeys = true' in 'Json {}' builder or '@JsonIgnoreUnknownKeys' annotation to ignore unknown keys." internal const val allowStructuredMapKeysHint = "Use 'allowStructuredMapKeys = true' in 'Json {}' builder to convert such maps to [key1, value1, key2, value2,...] arrays." @@ -230,13 +231,17 @@ internal abstract class AbstractJsonLexer { fail(charToTokenClass(expected)) } - internal fun fail(expectedToken: Byte, wasConsumed: Boolean = true): Nothing { + internal inline fun fail( + expectedToken: Byte, + wasConsumed: Boolean = true, + message: (expected: String, source: String) -> String = { expected, source -> "Expected $expected, but had '$source' instead" } + ): Nothing { // Slow path, never called in normal code, can avoid optimizing it val expected = tokenDescription(expectedToken) val position = if (wasConsumed) currentPosition - 1 else currentPosition val s = if (currentPosition == source.length || position < 0) "EOF" else source[position].toString() - fail("Expected $expected, but had '$s' instead", position) + fail(message(expected, s), position) } open fun peekNextToken(): Byte { @@ -593,7 +598,10 @@ internal abstract class AbstractJsonLexer { // but still would like an error to point to the beginning of the key, so we are backtracking it val processed = substring(0, currentPosition) val lastIndexOf = processed.lastIndexOf(key) - fail("Encountered an unknown key '$key'", lastIndexOf, ignoreUnknownKeysHint) + throw JsonDecodingException( + "Encountered an unknown key '$key' at offset $lastIndexOf at path: ${path.getPath()}\n$ignoreUnknownKeysHint\n" + + "JSON input: ${source.minify(lastIndexOf)}" + ) } fun fail(message: String, position: Int = currentPosition, hint: String = ""): Nothing { @@ -698,6 +706,16 @@ internal abstract class AbstractJsonLexer { } } + fun consumeNumericLiteralFully(): Long { + val result = consumeNumericLiteral() + val next = consumeNextToken() + if (next != TC_EOF) { + fail(TC_EOF) { _, source -> "Expected input to contain a single valid number, but got '$source' after it" } + } + return result + } + + fun consumeBoolean(): Boolean { return consumeBoolean(skipWhitespaces()) } diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/CommentLexers.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/CommentLexers.kt similarity index 98% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/CommentLexers.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/CommentLexers.kt index 816d32fc5..5ddf71e53 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/CommentLexers.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/CommentLexers.kt @@ -2,9 +2,9 @@ * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal.lexer +package kotlinx.serialization.json.internal.lexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.InternalJsonReader +import kotlinx.serialization.json.internal.InternalJsonReader /* Implementations of these two classes are nearly identical. However, there are several reasons why it can't be unified diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/ReaderJsonLexer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/ReaderJsonLexer.kt similarity index 96% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/ReaderJsonLexer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/ReaderJsonLexer.kt index 374ac5b35..339afbf77 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/ReaderJsonLexer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/ReaderJsonLexer.kt @@ -2,12 +2,12 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal.lexer +package kotlinx.serialization.json.internal.lexer -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.internal.CharArrayPoolBatchSize -import dev.ragnarok.fenrir.util.serializeble.json.internal.InternalJsonReader import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.internal.CharArrayPoolBatchSize +import kotlinx.serialization.json.internal.InternalJsonReader internal const val BATCH_SIZE: Int = 16 * 1024 private const val DEFAULT_THRESHOLD = 128 diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/StringJsonLexer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/StringJsonLexer.kt similarity index 97% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/StringJsonLexer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/StringJsonLexer.kt index e9e103a14..666996d9d 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/StringJsonLexer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/json/internal/lexer/StringJsonLexer.kt @@ -2,10 +2,10 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal.lexer +package kotlinx.serialization.json.internal.lexer -import dev.ragnarok.fenrir.util.serializeble.json.Json import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.Json @OptIn(ExperimentalSerializationApi::class) internal fun StringJsonLexer(json: Json, source: String) = diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPack.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPack.kt similarity index 88% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPack.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPack.kt index 9e15d0e52..50baffd14 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPack.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPack.kt @@ -1,16 +1,7 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack +package kotlinx.serialization.msgpack import dev.ragnarok.fenrir.module.BufferWriteNative import dev.ragnarok.fenrir.module.FenrirNative -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.msgpack.internal.BasicMsgPackDecoder -import dev.ragnarok.fenrir.util.serializeble.msgpack.internal.BasicMsgPackEncoder -import dev.ragnarok.fenrir.util.serializeble.msgpack.internal.InlineDecoderHelper -import dev.ragnarok.fenrir.util.serializeble.msgpack.internal.InlineEncoderHelper -import dev.ragnarok.fenrir.util.serializeble.msgpack.internal.MsgPackDecoder -import dev.ragnarok.fenrir.util.serializeble.msgpack.internal.MsgPackEncoder -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.toMsgPackArrayBuffer -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.toMsgPackBufferedSource import kotlinx.serialization.BinaryFormat import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi @@ -21,7 +12,16 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.buildClassSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonElement import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder +import kotlinx.serialization.msgpack.internal.BasicMsgPackEncoder +import kotlinx.serialization.msgpack.internal.InlineDecoderHelper +import kotlinx.serialization.msgpack.internal.InlineEncoderHelper +import kotlinx.serialization.msgpack.internal.MsgPackDecoder +import kotlinx.serialization.msgpack.internal.MsgPackEncoder +import kotlinx.serialization.msgpack.stream.toMsgPackArrayBuffer +import kotlinx.serialization.msgpack.stream.toMsgPackBufferedSource import kotlinx.serialization.serializer import okio.BufferedSource diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPackConfiguration.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackConfiguration.kt similarity index 96% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPackConfiguration.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackConfiguration.kt index 1ab49cd51..39ce0c8c8 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPackConfiguration.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackConfiguration.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack +package kotlinx.serialization.msgpack /** * MsgPack configuration diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPackDynamicSerializer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackDynamicSerializer.kt similarity index 94% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPackDynamicSerializer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackDynamicSerializer.kt index 372ee33ae..81c1d4a61 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPackDynamicSerializer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackDynamicSerializer.kt @@ -1,9 +1,5 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack +package kotlinx.serialization.msgpack -import dev.ragnarok.fenrir.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.fenrir.util.serializeble.msgpack.extensions.DynamicMsgPackExtensionSerializer -import dev.ragnarok.fenrir.util.serializeble.msgpack.internal.MsgPackTypeDecoder -import dev.ragnarok.fenrir.util.serializeble.msgpack.types.MsgPackType import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.ArraySerializer @@ -16,6 +12,10 @@ import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.buildSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.extensions.DynamicMsgPackExtensionSerializer +import kotlinx.serialization.msgpack.internal.MsgPackTypeDecoder +import kotlinx.serialization.msgpack.types.MsgPackType import kotlinx.serialization.serializer open class MsgPackDynamicSerializer( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPackTreeReader.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackTreeReader.kt similarity index 92% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPackTreeReader.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackTreeReader.kt index 89f8a6a5e..c66e93284 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/MsgPackTreeReader.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackTreeReader.kt @@ -1,14 +1,14 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack - -import dev.ragnarok.fenrir.util.serializeble.json.JsonArray -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonNull -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.JsonPrimitive -import dev.ragnarok.fenrir.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.fenrir.util.serializeble.msgpack.internal.BasicMsgPackDecoder -import dev.ragnarok.fenrir.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.fenrir.util.serializeble.msgpack.utils.joinToNumber +package kotlinx.serialization.msgpack + +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.joinToNumber internal class MsgPackTreeReader( private val basicMsgPackDecoder: BasicMsgPackDecoder diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/exceptions/MsgPackSerializationException.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/exceptions/MsgPackSerializationException.kt similarity index 91% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/exceptions/MsgPackSerializationException.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/exceptions/MsgPackSerializationException.kt index 699efd25c..4de19ce52 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/exceptions/MsgPackSerializationException.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/exceptions/MsgPackSerializationException.kt @@ -1,11 +1,11 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.exceptions +package kotlinx.serialization.msgpack.exceptions -import dev.ragnarok.fenrir.util.serializeble.msgpack.extensions.MsgPackExtension -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.MsgPackDataBuffer -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.MsgPackDataInputBuffer -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.MsgPackDataInputOkio -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.MsgPackDataOutputBuffer import kotlinx.serialization.SerializationException +import kotlinx.serialization.msgpack.extensions.MsgPackExtension +import kotlinx.serialization.msgpack.stream.MsgPackDataBuffer +import kotlinx.serialization.msgpack.stream.MsgPackDataInputBuffer +import kotlinx.serialization.msgpack.stream.MsgPackDataInputOkio +import kotlinx.serialization.msgpack.stream.MsgPackDataOutputBuffer private fun ByteArray.toHex() = this.joinToString(separator = "") { it.toHex() } private fun Byte.toHex() = toInt().and(0xff).toString(16).padStart(2, '0') diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/BaseMsgPackExtensionSerializer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/BaseMsgPackExtensionSerializer.kt similarity index 90% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/BaseMsgPackExtensionSerializer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/BaseMsgPackExtensionSerializer.kt index 43dbc134e..f573f8349 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/BaseMsgPackExtensionSerializer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/BaseMsgPackExtensionSerializer.kt @@ -1,10 +1,10 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.extensions +package kotlinx.serialization.msgpack.extensions -import dev.ragnarok.fenrir.util.serializeble.msgpack.exceptions.MsgPackSerializationException import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException abstract class BaseMsgPackExtensionSerializer : KSerializer { private val serializer = MsgPackExtension.serializer() diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt similarity index 97% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt index b0e93a918..a4725435e 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.extensions +package kotlinx.serialization.msgpack.extensions import kotlinx.serialization.SerializationException import kotlin.reflect.KClass diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/MsgPackExtension.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackExtension.kt similarity index 81% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/MsgPackExtension.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackExtension.kt index 516244bc2..f65fcc7bc 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/MsgPackExtension.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackExtension.kt @@ -1,7 +1,7 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.extensions +package kotlinx.serialization.msgpack.extensions -import dev.ragnarok.fenrir.util.serializeble.msgpack.types.MsgPackType import kotlinx.serialization.Serializable +import kotlinx.serialization.msgpack.types.MsgPackType @Serializable class MsgPackExtension( diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/MsgPackTimestampExtension.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackTimestampExtension.kt similarity index 93% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/MsgPackTimestampExtension.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackTimestampExtension.kt index 7c1c92866..3e61abe8b 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/extensions/MsgPackTimestampExtension.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackTimestampExtension.kt @@ -1,9 +1,9 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.extensions +package kotlinx.serialization.msgpack.extensions -import dev.ragnarok.fenrir.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.fenrir.util.serializeble.msgpack.utils.joinToNumber -import dev.ragnarok.fenrir.util.serializeble.msgpack.utils.splitToByteArray import kotlinx.serialization.Serializable +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.utils.joinToNumber +import kotlinx.serialization.msgpack.utils.splitToByteArray @Serializable(with = MsgPackTimestampExtensionSerializer::class) sealed class MsgPackTimestamp { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgPackDecoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackDecoder.kt similarity index 93% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgPackDecoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackDecoder.kt index 1be8c5089..93d1bb317 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgPackDecoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackDecoder.kt @@ -1,13 +1,5 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.internal - -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPackConfiguration -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPackNullableDynamicSerializer -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPackTreeReader -import dev.ragnarok.fenrir.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.MsgPackDataInputBuffer -import dev.ragnarok.fenrir.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.fenrir.util.serializeble.msgpack.utils.joinToNumber +package kotlinx.serialization.msgpack.internal + import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.builtins.ByteArraySerializer import kotlinx.serialization.descriptors.SerialDescriptor @@ -15,7 +7,15 @@ import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.encoding.AbstractDecoder import kotlinx.serialization.encoding.CompositeDecoder import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.json.JsonElement import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.msgpack.MsgPackConfiguration +import kotlinx.serialization.msgpack.MsgPackNullableDynamicSerializer +import kotlinx.serialization.msgpack.MsgPackTreeReader +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.stream.MsgPackDataInputBuffer +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.joinToNumber interface MsgPackTypeDecoder { fun peekNextType(): Byte @@ -230,7 +230,7 @@ internal class BasicMsgPackDecoder( override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder { if (descriptor.kind in arrayOf(StructureKind.CLASS, StructureKind.OBJECT)) { - if (descriptor.serialName == "dev.ragnarok.fenrir.util.serializeble.msgpack.extensions.MsgPackExtension") { + if (descriptor.serialName == "kotlinx.serialization.msgpack.extensions.MsgPackExtension") { return ExtensionTypeDecoder(this) } diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgPackEncoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackEncoder.kt similarity index 94% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgPackEncoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackEncoder.kt index 7e80b02be..3a31e6a36 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgPackEncoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackEncoder.kt @@ -1,12 +1,5 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.internal - -import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPackConfiguration -import dev.ragnarok.fenrir.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.MsgPackDataOutputArrayBuffer -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.MsgPackDataOutputArrayBufferCompressed -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.MsgPackDataOutputBuffer -import dev.ragnarok.fenrir.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.fenrir.util.serializeble.msgpack.utils.splitToByteArray +package kotlinx.serialization.msgpack.internal + import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.builtins.ByteArraySerializer @@ -16,6 +9,13 @@ import kotlinx.serialization.encoding.AbstractEncoder import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.msgpack.MsgPackConfiguration +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.stream.MsgPackDataOutputArrayBuffer +import kotlinx.serialization.msgpack.stream.MsgPackDataOutputArrayBufferCompressed +import kotlinx.serialization.msgpack.stream.MsgPackDataOutputBuffer +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.splitToByteArray internal class BasicMsgPackEncoder( private val configuration: MsgPackConfiguration, @@ -98,7 +98,7 @@ internal class BasicMsgPackEncoder( override fun beginStructure(descriptor: SerialDescriptor): CompositeEncoder { return if (descriptor.kind in arrayOf(StructureKind.CLASS, StructureKind.OBJECT)) { - if (descriptor.serialName == "dev.ragnarok.fenrir.util.serializeble.msgpack.extensions.MsgPackExtension") { + if (descriptor.serialName == "kotlinx.serialization.msgpack.extensions.MsgPackExtension") { ExtensionTypeEncoder(this) } else { beginCollection(descriptor, descriptor.elementsCount) diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgPacker.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPacker.kt similarity index 94% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgPacker.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPacker.kt index 9625c24c8..941003366 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgPacker.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPacker.kt @@ -1,8 +1,8 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.internal +package kotlinx.serialization.msgpack.internal -import dev.ragnarok.fenrir.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.fenrir.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.fenrir.util.serializeble.msgpack.utils.splitToByteArray +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.splitToByteArray internal interface MsgPacker { fun packNull(): ByteArray diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgUnpacker.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgUnpacker.kt similarity index 96% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgUnpacker.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgUnpacker.kt index cf7a3d1b4..6d1114776 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/internal/MsgUnpacker.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgUnpacker.kt @@ -1,9 +1,9 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.internal +package kotlinx.serialization.msgpack.internal -import dev.ragnarok.fenrir.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.fenrir.util.serializeble.msgpack.stream.MsgPackDataInputBuffer -import dev.ragnarok.fenrir.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.fenrir.util.serializeble.msgpack.utils.joinToNumber +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.stream.MsgPackDataInputBuffer +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.joinToNumber internal interface MsgUnpacker { fun unpackNull() diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/stream/MsgPackDataBuffer.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/stream/MsgPackDataBuffer.kt similarity index 98% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/stream/MsgPackDataBuffer.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/stream/MsgPackDataBuffer.kt index 979937307..9d27da12c 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/stream/MsgPackDataBuffer.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/stream/MsgPackDataBuffer.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.stream +package kotlinx.serialization.msgpack.stream import com.google.common.math.IntMath.mod import dev.ragnarok.fenrir.module.BufferWriteNative diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/types/MsgPackType.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/types/MsgPackType.kt similarity index 99% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/types/MsgPackType.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/types/MsgPackType.kt index 9932d0450..a38f9c201 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/types/MsgPackType.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/types/MsgPackType.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.types +package kotlinx.serialization.msgpack.types internal object MsgPackType { internal object Boolean { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/utils/ByteArrayUtils.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/utils/ByteArrayUtils.kt similarity index 94% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/utils/ByteArrayUtils.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/utils/ByteArrayUtils.kt index 618207e43..4d2033704 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/msgpack/utils/ByteArrayUtils.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/msgpack/utils/ByteArrayUtils.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.fenrir.util.serializeble.msgpack.utils +package kotlinx.serialization.msgpack.utils internal inline fun T.splitToByteArray(): ByteArray { val byteCount = when (T::class) { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/AsProperty.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/AsProperty.kt similarity index 97% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/AsProperty.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/AsProperty.kt index 2c4adcf22..9792b92fc 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/AsProperty.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/AsProperty.kt @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.fenrir.util.serializeble.prefs +package kotlinx.serialization.prefs import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.nullable @@ -15,7 +15,7 @@ import kotlin.reflect.KProperty import android.content.* import kotlin.test.* import kotlinx.serialization.builtins.* -import dev.ragnarok.fenrir.util.serializeble.prefs.* +import kotlinx.serialization.prefs.* import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/Preferences.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/Preferences.kt similarity index 97% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/Preferences.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/Preferences.kt index b33522e1b..78f2859df 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/Preferences.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/Preferences.kt @@ -2,16 +2,16 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.fenrir.util.serializeble.prefs +package kotlinx.serialization.prefs import android.content.SharedPreferences -import dev.ragnarok.fenrir.util.serializeble.prefs.encoding.PreferenceDecoder -import dev.ragnarok.fenrir.util.serializeble.prefs.encoding.PreferenceEncoder import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerialFormat import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.modules.EmptySerializersModule import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.prefs.encoding.PreferenceDecoder +import kotlinx.serialization.prefs.encoding.PreferenceEncoder import kotlinx.serialization.serializer import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind @@ -22,7 +22,7 @@ import kotlin.contracts.contract import android.content.* import kotlin.test.* import kotlinx.serialization.* -import dev.ragnarok.fenrir.util.serializeble.prefs.* +import kotlinx.serialization.prefs.* import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/encoding/Helpers.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/encoding/Helpers.kt similarity index 90% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/encoding/Helpers.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/encoding/Helpers.kt index 41982f442..4451907f7 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/encoding/Helpers.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/encoding/Helpers.kt @@ -2,9 +2,8 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.fenrir.util.serializeble.prefs.encoding +package kotlinx.serialization.prefs.encoding -import dev.ragnarok.fenrir.util.serializeble.prefs.PreferenceConfiguration import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.PrimitiveKind @@ -12,6 +11,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.encoding.CompositeDecoder +import kotlinx.serialization.prefs.PreferenceConfiguration @OptIn(ExperimentalSerializationApi::class) internal fun PreferenceConfiguration.shouldSerializeStringSet(descriptor: SerialDescriptor): Boolean { diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/encoding/PreferenceDecoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceDecoder.kt similarity index 96% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/encoding/PreferenceDecoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceDecoder.kt index da9ac8559..6de8dc171 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/encoding/PreferenceDecoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceDecoder.kt @@ -2,11 +2,9 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.fenrir.util.serializeble.prefs.encoding +package kotlinx.serialization.prefs.encoding import android.content.SharedPreferences -import dev.ragnarok.fenrir.util.serializeble.prefs.DoubleRepresentation -import dev.ragnarok.fenrir.util.serializeble.prefs.Preferences import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.SerializationException @@ -16,6 +14,8 @@ import kotlinx.serialization.encoding.AbstractDecoder import kotlinx.serialization.encoding.CompositeDecoder import kotlinx.serialization.internal.NamedValueDecoder import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.prefs.DoubleRepresentation +import kotlinx.serialization.prefs.Preferences @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class) @Suppress("TooManyFunctions") diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/encoding/PreferenceEncoder.kt b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceEncoder.kt similarity index 96% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/encoding/PreferenceEncoder.kt rename to app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceEncoder.kt index 74083b2aa..2524fab5c 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/prefs/encoding/PreferenceEncoder.kt +++ b/app_fenrir/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceEncoder.kt @@ -2,11 +2,9 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.fenrir.util.serializeble.prefs.encoding +package kotlinx.serialization.prefs.encoding import android.content.SharedPreferences -import dev.ragnarok.fenrir.util.serializeble.prefs.DoubleRepresentation -import dev.ragnarok.fenrir.util.serializeble.prefs.Preferences import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.SerializationException @@ -16,6 +14,8 @@ import kotlinx.serialization.encoding.AbstractEncoder import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.internal.NamedValueEncoder import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.prefs.DoubleRepresentation +import kotlinx.serialization.prefs.Preferences @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class) @Suppress("TooManyFunctions") diff --git a/app_filegallery/build.gradle b/app_filegallery/build.gradle index 38c8ea4a7..8a6aa1f68 100644 --- a/app_filegallery/build.gradle +++ b/app_filegallery/build.gradle @@ -46,7 +46,7 @@ android { //noinspection ChromeOsAbiSupport abiFilters = targetAbi } - resConfigs "en", "ru" + androidResources.localeFilters = ["en", "ru"] } lint { @@ -66,6 +66,7 @@ android { "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", "-opt-in=kotlinx.serialization.internal.CoreFriendModuleApi", + "-opt-in=kotlinx.serialization.SealedSerializationApi", "-opt-in=kotlinx.serialization.InternalSerializationApi", "-opt-in=kotlin.RequiresOptIn", "-opt-in=kotlin.ExperimentalStdlibApi"] } diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/Extensions.kt b/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/Extensions.kt index 4dac67930..372e0ae7f 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/Extensions.kt +++ b/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/Extensions.kt @@ -13,13 +13,24 @@ import android.os.Parcel import android.os.Parcelable import android.view.View import androidx.annotation.ColorInt +import androidx.core.database.getBlobOrNull import androidx.core.database.getStringOrNull -import dev.ragnarok.filegallery.util.serializeble.json.Json +import kotlinx.serialization.json.Json import okhttp3.ResponseBody import java.io.Serializable import kotlin.contracts.contract val kJson: Json by lazy { Json { ignoreUnknownKeys = true; isLenient = true } } +val kJsonPretty: Json by lazy { + Json { + ignoreUnknownKeys = true; isLenient = true; prettyPrint = true + } +} +val kJsonNotPretty: Json by lazy { + Json { + ignoreUnknownKeys = true; isLenient = true; prettyPrint = false + } +} fun SQLiteDatabase.query( tableName: String, @@ -41,6 +52,9 @@ fun Cursor.getBoolean(columnName: String): Boolean = fun Cursor.getString(columnName: String): String? = getStringOrNull(getColumnIndexOrThrow(columnName)) +fun Cursor.getBlob(columnName: String): ByteArray? = + getBlobOrNull(getColumnIndexOrThrow(columnName)) + inline fun Collection?.safeAllIsNullOrEmpty(): Boolean { contract { returns(false) implies (this@safeAllIsNullOrEmpty != null) diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/activity/MainActivity.kt b/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/activity/MainActivity.kt index ffc965b57..001c58b0f 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/activity/MainActivity.kt +++ b/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/activity/MainActivity.kt @@ -380,7 +380,7 @@ class MainActivity : AppCompatActivity(), OnSectionResumeCallback, AppStyleable, private fun handleIntent(action: String?, main: Boolean) { if (main) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && needHelp( + if (Utils.hasTiramisuTarget() && needHelp( NOTIFICATION_PERMISSION, 1 ) && !AppPerms.hasNotificationPermissionSimple(this) diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/api/adapters/AbsDtoAdapter.kt b/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/api/adapters/AbsDtoAdapter.kt index 2f016c91d..699acff5c 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/api/adapters/AbsDtoAdapter.kt +++ b/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/api/adapters/AbsDtoAdapter.kt @@ -2,25 +2,25 @@ package dev.ragnarok.filegallery.api.adapters import dev.ragnarok.filegallery.Constants import dev.ragnarok.filegallery.kJson -import dev.ragnarok.filegallery.util.serializeble.json.JsonArray -import dev.ragnarok.filegallery.util.serializeble.json.JsonDecoder -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.json.JsonNull -import dev.ragnarok.filegallery.util.serializeble.json.JsonObject -import dev.ragnarok.filegallery.util.serializeble.json.JsonPrimitive -import dev.ragnarok.filegallery.util.serializeble.json.booleanOrNull -import dev.ragnarok.filegallery.util.serializeble.json.doubleOrNull -import dev.ragnarok.filegallery.util.serializeble.json.floatOrNull -import dev.ragnarok.filegallery.util.serializeble.json.intOrNull -import dev.ragnarok.filegallery.util.serializeble.json.jsonArray -import dev.ragnarok.filegallery.util.serializeble.json.jsonPrimitive -import dev.ragnarok.filegallery.util.serializeble.json.longOrNull -import dev.ragnarok.filegallery.util.serializeble.msgpack.internal.BasicMsgPackDecoder import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.buildClassSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.booleanOrNull +import kotlinx.serialization.json.doubleOrNull +import kotlinx.serialization.json.floatOrNull +import kotlinx.serialization.json.intOrNull +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonPrimitive +import kotlinx.serialization.json.longOrNull +import kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder import kotlin.contracts.contract abstract class AbsDtoAdapter(name: String) : KSerializer { diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/api/adapters/AudioDtoAdapter.kt b/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/api/adapters/AudioDtoAdapter.kt index b25485188..9841b4009 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/api/adapters/AudioDtoAdapter.kt +++ b/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/api/adapters/AudioDtoAdapter.kt @@ -1,8 +1,8 @@ package dev.ragnarok.filegallery.api.adapters import dev.ragnarok.filegallery.model.Audio -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.json.jsonObject +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject class AudioDtoAdapter : AbsDtoAdapter

+ * This annotation also could be used as a meta-annotation, to define derived annotations for convenience. + * E.g. the following annotation could be defined to annotate the strings that represent Java methods: + * + *

+ *   @Language(value = "JAVA", prefix = "class X{", suffix = "}")
+ *   @interface JavaMethod {}
+ * 
+ *

+ * Note that using the derived annotation as meta-annotation is not supported. + * Meta-annotation works only one level deep. + */ + +@InternalSerializationApi +@Retention(AnnotationRetention.BINARY) +@Target( + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY_GETTER, + AnnotationTarget.PROPERTY_SETTER, + AnnotationTarget.FIELD, + AnnotationTarget.VALUE_PARAMETER, + AnnotationTarget.LOCAL_VARIABLE, + AnnotationTarget.ANNOTATION_CLASS +) +annotation class FormatLanguage( + val value: String, + // default parameters are not used due to https://youtrack.jetbrains.com/issue/KT-25946/ + val prefix: String, + val suffix: String, +) diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonElementMarker.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonElementMarker.kt similarity index 93% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonElementMarker.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonElementMarker.kt index 262d2c8d1..c5075dc21 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonElementMarker.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonElementMarker.kt @@ -3,7 +3,7 @@ */ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.SerialDescriptor diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonExceptions.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonExceptions.kt similarity index 85% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonExceptions.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonExceptions.kt index 979624cc7..46b5113e3 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonExceptions.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonExceptions.kt @@ -4,15 +4,14 @@ @file:Suppress("FunctionName") -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.AbstractJsonLexer -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.allowStructuredMapKeysHint -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.ignoreUnknownKeysHint -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.specialFlowingValuesHint import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.json.internal.lexer.AbstractJsonLexer +import kotlinx.serialization.json.internal.lexer.allowStructuredMapKeysHint +import kotlinx.serialization.json.internal.lexer.specialFlowingValuesHint /** * Generic exception indicating a problem with JSON serialization and deserialization. @@ -82,13 +81,6 @@ private fun unexpectedFpErrorMessage(value: Number, key: String, output: String) "Current output: ${output.minify()}" } -internal fun UnknownKeyException(key: String, input: String) = JsonDecodingException( - -1, - "Encountered an unknown key '$key'.\n" + - "$ignoreUnknownKeysHint\n" + - "Current input: ${input.minify()}" -) - internal fun CharSequence.minify(offset: Int = -1): CharSequence { if (length < 200) return this if (offset == -1) { diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonIterator.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonIterator.kt similarity index 85% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonIterator.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonIterator.kt index 1f122ffc5..bc954d383 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonIterator.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonIterator.kt @@ -5,17 +5,17 @@ @file:Suppress("FunctionName") @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.filegallery.util.serializeble.json.DecodeSequenceMode -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.AbstractJsonLexer -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.COMMA -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.ReaderJsonLexer -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_BEGIN_LIST -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_END_LIST import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.DecodeSequenceMode +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.internal.lexer.AbstractJsonLexer +import kotlinx.serialization.json.internal.lexer.COMMA +import kotlinx.serialization.json.internal.lexer.ReaderJsonLexer +import kotlinx.serialization.json.internal.lexer.TC_BEGIN_LIST +import kotlinx.serialization.json.internal.lexer.TC_END_LIST internal fun JsonIterator( mode: DecodeSequenceMode, diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonNamesMap.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonNamesMap.kt similarity index 94% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonNamesMap.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonNamesMap.kt index b3bc95a00..7e62660fc 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/JsonNamesMap.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonNamesMap.kt @@ -3,18 +3,19 @@ */ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.JsonNames -import dev.ragnarok.fenrir.util.serializeble.json.JsonNamingStrategy -import dev.ragnarok.fenrir.util.serializeble.json.schemaCache import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.encoding.CompositeDecoder +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonIgnoreUnknownKeys +import kotlinx.serialization.json.JsonNames +import kotlinx.serialization.json.JsonNamingStrategy +import kotlinx.serialization.json.schemaCache internal val JsonDeserializationNamesKey = DescriptorSchemaCache.Key>() @@ -173,3 +174,6 @@ internal inline fun Json.tryCoerceValue( } return false } + +internal fun SerialDescriptor.ignoreUnknownKeys(json: Json): Boolean = + json.configuration.ignoreUnknownKeys || annotations.any { it is JsonIgnoreUnknownKeys } diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonPath.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonPath.kt similarity index 98% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonPath.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonPath.kt index 93f7a8882..80e603eea 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonPath.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonPath.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.SerialDescriptor diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/PolymorphismValidator.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonSerializersModuleValidator.kt similarity index 85% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/PolymorphismValidator.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonSerializersModuleValidator.kt index 3e2814c0b..5bed29dcc 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/PolymorphismValidator.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonSerializersModuleValidator.kt @@ -2,7 +2,7 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal +package kotlinx.serialization.json.internal import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi @@ -13,15 +13,21 @@ import kotlinx.serialization.descriptors.PrimitiveKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.StructureKind +import kotlinx.serialization.json.ClassDiscriminatorMode +import kotlinx.serialization.json.JsonConfiguration import kotlinx.serialization.modules.SerializersModuleCollector import kotlin.reflect.KClass @OptIn(ExperimentalSerializationApi::class) -internal class PolymorphismValidator( - private val useArrayPolymorphism: Boolean, - private val discriminator: String +internal class JsonSerializersModuleValidator( + configuration: JsonConfiguration, ) : SerializersModuleCollector { + private val discriminator: String = configuration.classDiscriminator + private val useArrayPolymorphism: Boolean = configuration.useArrayPolymorphism + private val isDiscriminatorRequired = + configuration.classDiscriminatorMode != ClassDiscriminatorMode.NONE + override fun contextual( kClass: KClass, provider: (typeArgumentsSerializers: List>) -> KSerializer<*> @@ -36,7 +42,7 @@ internal class PolymorphismValidator( ) { val descriptor = actualSerializer.descriptor checkKind(descriptor, actualClass) - if (!useArrayPolymorphism) { + if (!useArrayPolymorphism && isDiscriminatorRequired) { // Collisions with "type" can happen only for JSON polymorphism checkDiscriminatorCollisions(descriptor, actualClass) } @@ -52,6 +58,7 @@ internal class PolymorphismValidator( } if (useArrayPolymorphism) return + if (!isDiscriminatorRequired) return /* * For this kind we can't intercept the JSON object {} in order to add "type: ...". * Except for maps that just can clash and accidentally overwrite the type. diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonStreams.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonStreams.kt similarity index 93% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonStreams.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonStreams.kt index 2203b90db..311939b44 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonStreams.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonStreams.kt @@ -1,12 +1,12 @@ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.filegallery.util.serializeble.json.DecodeSequenceMode -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.BATCH_SIZE -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.ReaderJsonLexer import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.json.DecodeSequenceMode +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.internal.lexer.BATCH_SIZE +import kotlinx.serialization.json.internal.lexer.ReaderJsonLexer import kotlinx.serialization.serializer internal annotation class JsonFriendModuleApi diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonToStringWriter.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonToStringWriter.kt similarity index 98% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonToStringWriter.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonToStringWriter.kt index 653ea0b13..e612df531 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonToStringWriter.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonToStringWriter.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal /** * Optimized version of StringBuilder that is specific to JSON-encoding. diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonTreeReader.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonTreeReader.kt similarity index 77% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonTreeReader.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonTreeReader.kt index 3552c180c..92fa6bb92 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/JsonTreeReader.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/JsonTreeReader.kt @@ -2,27 +2,27 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.filegallery.util.serializeble.json.JsonArray -import dev.ragnarok.filegallery.util.serializeble.json.JsonConfiguration -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.json.JsonLiteral -import dev.ragnarok.filegallery.util.serializeble.json.JsonNull -import dev.ragnarok.filegallery.util.serializeble.json.JsonObject -import dev.ragnarok.filegallery.util.serializeble.json.JsonPrimitive -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.AbstractJsonLexer -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.NULL -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_BEGIN_LIST -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_BEGIN_OBJ -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_COLON -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_COMMA -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_END_LIST -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_END_OBJ -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_OTHER -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_STRING -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.tokenDescription import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonConfiguration +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonLiteral +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.internal.lexer.AbstractJsonLexer +import kotlinx.serialization.json.internal.lexer.NULL +import kotlinx.serialization.json.internal.lexer.TC_BEGIN_LIST +import kotlinx.serialization.json.internal.lexer.TC_BEGIN_OBJ +import kotlinx.serialization.json.internal.lexer.TC_COLON +import kotlinx.serialization.json.internal.lexer.TC_COMMA +import kotlinx.serialization.json.internal.lexer.TC_END_LIST +import kotlinx.serialization.json.internal.lexer.TC_END_OBJ +import kotlinx.serialization.json.internal.lexer.TC_OTHER +import kotlinx.serialization.json.internal.lexer.TC_STRING +import kotlinx.serialization.json.internal.lexer.tokenDescription @OptIn(ExperimentalSerializationApi::class) internal class JsonTreeReader( diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/OkioJsonStreams.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/OkioJsonStreams.kt similarity index 94% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/OkioJsonStreams.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/OkioJsonStreams.kt index 36c633d3d..9e9006c4b 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/OkioJsonStreams.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/OkioJsonStreams.kt @@ -2,7 +2,7 @@ * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal import okio.BufferedSink import okio.BufferedSource diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/Polymorphic.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/Polymorphic.kt similarity index 87% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/Polymorphic.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/Polymorphic.kt index 866980905..d73138b20 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/Polymorphic.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/Polymorphic.kt @@ -3,17 +3,8 @@ */ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.filegallery.util.serializeble.json.ClassDiscriminatorMode -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.JsonClassDiscriminator -import dev.ragnarok.filegallery.util.serializeble.json.JsonDecoder -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.json.JsonEncoder -import dev.ragnarok.filegallery.util.serializeble.json.JsonObject -import dev.ragnarok.filegallery.util.serializeble.json.contentOrNull -import dev.ragnarok.filegallery.util.serializeble.json.jsonPrimitive import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SealedClassSerializer @@ -27,6 +18,15 @@ import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.findPolymorphicSerializer import kotlinx.serialization.internal.AbstractPolymorphicSerializer import kotlinx.serialization.internal.jsonCachedSerialNames +import kotlinx.serialization.json.ClassDiscriminatorMode +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonClassDiscriminator +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonEncoder +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.contentOrNull +import kotlinx.serialization.json.jsonPrimitive @Suppress("UNCHECKED_CAST") internal inline fun JsonEncoder.encodePolymorphically( @@ -54,12 +54,10 @@ internal inline fun JsonEncoder.encodePolymorphically( val casted = serializer as AbstractPolymorphicSerializer requireNotNull(value) { "Value for serializer ${serializer.descriptor} should always be non-null. Please report issue to the kotlinx.serialization tracker." } val actual = casted.findPolymorphicSerializer(this, value) - if (baseClassDiscriminator != null) validateIfSealed( - serializer, - actual, - baseClassDiscriminator - ) - checkKind(actual.descriptor.kind) + if (baseClassDiscriminator != null) { + validateIfSealed(serializer, actual, baseClassDiscriminator) + checkKind(actual.descriptor.kind) + } actual as SerializationStrategy } else serializer @@ -134,4 +132,4 @@ internal fun throwJsonElementPolymorphicException( element: JsonElement ): Nothing { throw JsonEncodingException("Class with serial name $serialName cannot be serialized polymorphically because it is represented as ${element::class.simpleName}. Make sure that its JsonTransformingSerializer returns JsonObject, so class discriminator can be added to it.") -} \ No newline at end of file +} diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/SchemaCache.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/SchemaCache.kt similarity index 90% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/SchemaCache.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/SchemaCache.kt index 790dc0455..76ff08e63 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/SchemaCache.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/SchemaCache.kt @@ -2,7 +2,7 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal import kotlinx.serialization.descriptors.SerialDescriptor @@ -24,7 +24,11 @@ internal class DescriptorSchemaCache { map.getOrPut(descriptor) { createMapForCache(2) }[key as Key] = value as Any } - fun getOrPut(descriptor: SerialDescriptor, key: Key, defaultValue: () -> T): T { + fun getOrPut( + descriptor: SerialDescriptor, + key: Key, + defaultValue: () -> T + ): T { get(descriptor, key)?.let { return it } val value = defaultValue() set(descriptor, key, value) diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/StreamingJsonDecoder.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt similarity index 93% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/StreamingJsonDecoder.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt index cb8776ff7..473820b9a 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/StreamingJsonDecoder.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt @@ -2,15 +2,8 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal - -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.JsonDecoder -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.AbstractJsonLexer -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.COLON -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.StringJsonLexer -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.TC_COMMA +package kotlinx.serialization.json.internal + import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.MissingFieldException @@ -24,6 +17,13 @@ import kotlinx.serialization.encoding.CompositeDecoder.Companion.UNKNOWN_NAME import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.findPolymorphicSerializer import kotlinx.serialization.internal.AbstractPolymorphicSerializer +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.internal.lexer.AbstractJsonLexer +import kotlinx.serialization.json.internal.lexer.COLON +import kotlinx.serialization.json.internal.lexer.StringJsonLexer +import kotlinx.serialization.json.internal.lexer.TC_COMMA import kotlinx.serialization.modules.SerializersModule /** @@ -138,7 +138,7 @@ internal open class StreamingJsonDecoder( // If we're ignoring unknown keys, we have to skip all un-decoded elements, // e.g. for object serialization. It can be the case when the descriptor does // not have any elements and decodeElementIndex is not invoked at all - if (json.configuration.ignoreUnknownKeys && descriptor.elementsCount == 0) { + if (descriptor.elementsCount == 0 && descriptor.ignoreUnknownKeys(json)) { skipLeftoverElements(descriptor) } if (lexer.tryConsumeComma() && !json.configuration.allowTrailingComma) lexer.invalidTrailingComma( @@ -259,7 +259,7 @@ internal open class StreamingJsonDecoder( } if (isUnknown) { // slow-path for unknown keys handling - hasComma = handleUnknown(key) + hasComma = handleUnknown(descriptor, key) } } if (hasComma && !json.configuration.allowTrailingComma) lexer.invalidTrailingComma() @@ -267,12 +267,13 @@ internal open class StreamingJsonDecoder( return elementMarker?.nextUnmarkedIndex() ?: DECODE_DONE } - private fun handleUnknown(key: String): Boolean { - if (configuration.ignoreUnknownKeys || discriminatorHolder.trySkip(key)) { + private fun handleUnknown(descriptor: SerialDescriptor, key: String): Boolean { + if (descriptor.ignoreUnknownKeys(json) || discriminatorHolder.trySkip(key)) { lexer.skipElement(configuration.isLenient) } else { - // Here we cannot properly update json path indices - // as we do not have a proper SerialDescriptor in our hands + // Since path is updated on key decoding, it ends with the key that was successfully decoded last, + // and we need to remove it to correctly point to the outer structure. + lexer.path.popDescriptor() lexer.failOnUnknownKey(key) } return lexer.tryConsumeComma() @@ -412,7 +413,7 @@ private inline fun AbstractJsonLexer.parseString( val input = consumeStringLenient() try { return input.block() - } catch (_: IllegalArgumentException) { + } catch (e: IllegalArgumentException) { fail("Failed to parse type '$expectedType' for input '$input'") } } diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/StreamingJsonEncoder.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt similarity index 91% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/StreamingJsonEncoder.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt index 0236e8565..4555cd3b7 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/StreamingJsonEncoder.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt @@ -2,18 +2,8 @@ * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal - -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.json.JsonElementSerializer -import dev.ragnarok.filegallery.util.serializeble.json.JsonEncoder -import dev.ragnarok.filegallery.util.serializeble.json.JsonObject -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.COLON -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.COMMA -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.INVALID -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.NULL -import dev.ragnarok.filegallery.util.serializeble.json.jsonUnquotedLiteralDescriptor +package kotlinx.serialization.json.internal + import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.builtins.serializer @@ -21,6 +11,16 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.AbstractEncoder import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonElementSerializer +import kotlinx.serialization.json.JsonEncoder +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.internal.lexer.COLON +import kotlinx.serialization.json.internal.lexer.COMMA +import kotlinx.serialization.json.internal.lexer.INVALID +import kotlinx.serialization.json.internal.lexer.NULL +import kotlinx.serialization.json.jsonUnquotedLiteralDescriptor import kotlinx.serialization.modules.SerializersModule private val unsignedNumberDescriptors = setOf( diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/StringOps.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/StringOps.kt similarity index 89% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/StringOps.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/StringOps.kt index 293762a0f..e929c4433 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/StringOps.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/StringOps.kt @@ -2,9 +2,9 @@ * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.STRING +import kotlinx.serialization.json.internal.lexer.STRING private fun toHexChar(i: Int): Char { val d = i and 0xf @@ -12,8 +12,8 @@ private fun toHexChar(i: Int): Char { else (d - 10 + 'a'.code).toChar() } -@PublishedApi -internal val ESCAPE_STRINGS: Array = arrayOfNulls(93).apply { +@JsonFriendModuleApi +val ESCAPE_STRINGS: Array = arrayOfNulls(93).apply { for (c in 0..0x1f) { val c1 = toHexChar(c shr 12) val c2 = toHexChar(c shr 8) diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/SuppressAnimalSniffer.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/SuppressAnimalSniffer.kt similarity index 87% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/SuppressAnimalSniffer.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/SuppressAnimalSniffer.kt index f26b60702..1ca90e71b 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/SuppressAnimalSniffer.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/SuppressAnimalSniffer.kt @@ -2,7 +2,7 @@ * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal /** * Suppresses Animal Sniffer plugin errors for certain methods. diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/TreeJsonDecoder.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonDecoder.kt similarity index 89% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/TreeJsonDecoder.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonDecoder.kt index 5d8e1bc7f..087691cd5 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/TreeJsonDecoder.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonDecoder.kt @@ -5,25 +5,8 @@ @file:Suppress("LeakingThis") @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.fenrir.util.serializeble.json.internal - -import dev.ragnarok.fenrir.util.serializeble.json.Json -import dev.ragnarok.fenrir.util.serializeble.json.JsonArray -import dev.ragnarok.fenrir.util.serializeble.json.JsonDecoder -import dev.ragnarok.fenrir.util.serializeble.json.JsonElement -import dev.ragnarok.fenrir.util.serializeble.json.JsonLiteral -import dev.ragnarok.fenrir.util.serializeble.json.JsonNull -import dev.ragnarok.fenrir.util.serializeble.json.JsonObject -import dev.ragnarok.fenrir.util.serializeble.json.JsonPrimitive -import dev.ragnarok.fenrir.util.serializeble.json.booleanOrNull -import dev.ragnarok.fenrir.util.serializeble.json.contentOrNull -import dev.ragnarok.fenrir.util.serializeble.json.double -import dev.ragnarok.fenrir.util.serializeble.json.float -import dev.ragnarok.fenrir.util.serializeble.json.int -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.StringJsonLexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.lenientHint -import dev.ragnarok.fenrir.util.serializeble.json.long -import dev.ragnarok.fenrir.util.serializeble.json.schemaCache +package kotlinx.serialization.json.internal + import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.PolymorphicKind @@ -33,10 +16,31 @@ import kotlinx.serialization.encoding.CompositeDecoder import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.internal.NamedValueDecoder import kotlinx.serialization.internal.jsonCachedSerialNames +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonLiteral +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.booleanOrNull +import kotlinx.serialization.json.contentOrNull +import kotlinx.serialization.json.double +import kotlinx.serialization.json.float +import kotlinx.serialization.json.internal.lexer.StringJsonLexer +import kotlinx.serialization.json.internal.lexer.ignoreUnknownKeysHint +import kotlinx.serialization.json.internal.lexer.lenientHint +import kotlinx.serialization.json.parseLongImpl +import kotlinx.serialization.json.schemaCache import kotlinx.serialization.modules.SerializersModule @JsonFriendModuleApi -fun readJson(json: Json, element: JsonElement, deserializer: DeserializationStrategy): T { +fun readJson( + json: Json, + element: JsonElement, + deserializer: DeserializationStrategy +): T { val input = when (element) { is JsonObject -> JsonTreeDecoder(json, element) is JsonArray -> JsonTreeListDecoder(json, element) @@ -158,19 +162,24 @@ private sealed class AbstractJsonTreeDecoder( getPrimitiveValue(tag, "boolean", JsonPrimitive::booleanOrNull) override fun decodeTaggedByte(tag: String) = getPrimitiveValue(tag, "byte") { - val result = int + val result = parseLongImpl() if (result in Byte.MIN_VALUE..Byte.MAX_VALUE) result.toByte() else null } override fun decodeTaggedShort(tag: String) = getPrimitiveValue(tag, "short") { - val result = int + val result = parseLongImpl() if (result in Short.MIN_VALUE..Short.MAX_VALUE) result.toShort() else null } - override fun decodeTaggedInt(tag: String) = getPrimitiveValue(tag, "int") { int } - override fun decodeTaggedLong(tag: String) = getPrimitiveValue(tag, "long") { long } + override fun decodeTaggedInt(tag: String) = getPrimitiveValue(tag, "int") { + val result = parseLongImpl() + if (result in Int.MIN_VALUE..Int.MAX_VALUE) result.toInt() + else null + } + + override fun decodeTaggedLong(tag: String) = getPrimitiveValue(tag, "long") { parseLongImpl() } override fun decodeTaggedFloat(tag: String): Float { val result = getPrimitiveValue(tag, "float") { float } @@ -326,7 +335,7 @@ private open class JsonTreeDecoder( } override fun endStructure(descriptor: SerialDescriptor) { - if (configuration.ignoreUnknownKeys || descriptor.kind is PolymorphicKind) return + if (descriptor.ignoreUnknownKeys(json) || descriptor.kind is PolymorphicKind) return // Validate keys val strategy = descriptor.namingStrategy(json) @@ -339,7 +348,12 @@ private open class JsonTreeDecoder( for (key in value.keys) { if (key !in names && key != polymorphicDiscriminator) { - throw UnknownKeyException(key, value.toString()) + throw JsonDecodingException( + -1, + "Encountered an unknown key '$key' at element: ${renderTagStack()}\n" + + "$ignoreUnknownKeysHint\n" + + "JSON input: ${value.toString().minify()}" + ) } } } diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/TreeJsonEncoder.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonEncoder.kt similarity index 92% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/TreeJsonEncoder.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonEncoder.kt index 3f10aa77d..70ae22335 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/TreeJsonEncoder.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/TreeJsonEncoder.kt @@ -3,21 +3,9 @@ */ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.filegallery.util.serializeble.json.internal - -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.JsonArray -import dev.ragnarok.filegallery.util.serializeble.json.JsonArraySerializer -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.json.JsonElementSerializer -import dev.ragnarok.filegallery.util.serializeble.json.JsonEncoder -import dev.ragnarok.filegallery.util.serializeble.json.JsonLiteral -import dev.ragnarok.filegallery.util.serializeble.json.JsonNull -import dev.ragnarok.filegallery.util.serializeble.json.JsonObject -import dev.ragnarok.filegallery.util.serializeble.json.JsonObjectSerializer -import dev.ragnarok.filegallery.util.serializeble.json.JsonPrimitive +package kotlinx.serialization.json.internal + import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.PrimitiveKind @@ -28,6 +16,17 @@ import kotlinx.serialization.encoding.AbstractEncoder import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.internal.NamedValueEncoder +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonArraySerializer +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonElementSerializer +import kotlinx.serialization.json.JsonEncoder +import kotlinx.serialization.json.JsonLiteral +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonObjectSerializer +import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.modules.SerializersModule import kotlin.collections.set @@ -39,8 +38,6 @@ fun writeJson(json: Json, value: T, serializer: SerializationStrategy): J return result } -@OptIn(InternalSerializationApi::class) -@ExperimentalSerializationApi private sealed class AbstractJsonTreeEncoder( final override val json: Json, val nodeConsumer: (JsonElement) -> Unit diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/WriteMode.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/WriteMode.kt similarity index 82% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/WriteMode.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/WriteMode.kt index af37118bf..66563e18b 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/WriteMode.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/WriteMode.kt @@ -3,13 +3,8 @@ */ @file:OptIn(ExperimentalSerializationApi::class) -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.BEGIN_LIST -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.BEGIN_OBJ -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.END_LIST -import dev.ragnarok.filegallery.util.serializeble.json.internal.lexer.END_OBJ import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.PrimitiveKind @@ -17,6 +12,11 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.descriptors.getContextualDescriptor +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.internal.lexer.BEGIN_LIST +import kotlinx.serialization.json.internal.lexer.BEGIN_OBJ +import kotlinx.serialization.json.internal.lexer.END_LIST +import kotlinx.serialization.json.internal.lexer.END_OBJ import kotlinx.serialization.modules.SerializersModule internal enum class WriteMode(@JvmField val begin: Char, @JvmField val end: Char) { diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/createMapForCache.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/createMapForCache.kt similarity index 87% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/createMapForCache.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/createMapForCache.kt index a32044cf1..28544bd05 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/createMapForCache.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/createMapForCache.kt @@ -2,7 +2,7 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal +package kotlinx.serialization.json.internal import java.util.concurrent.ConcurrentHashMap diff --git a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/AbstractJsonLexer.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/AbstractJsonLexer.kt similarity index 95% rename from app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/AbstractJsonLexer.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/AbstractJsonLexer.kt index 0fdba195d..297252fc9 100644 --- a/app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/serializeble/json/internal/lexer/AbstractJsonLexer.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/AbstractJsonLexer.kt @@ -2,12 +2,13 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.fenrir.util.serializeble.json.internal.lexer +package kotlinx.serialization.json.internal.lexer -import dev.ragnarok.fenrir.util.serializeble.json.internal.JsonDecodingException -import dev.ragnarok.fenrir.util.serializeble.json.internal.JsonPath -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.CharMappings.CHAR_TO_TOKEN -import dev.ragnarok.fenrir.util.serializeble.json.internal.lexer.CharMappings.ESCAPE_2_CHAR +import kotlinx.serialization.json.internal.JsonDecodingException +import kotlinx.serialization.json.internal.JsonPath +import kotlinx.serialization.json.internal.lexer.CharMappings.CHAR_TO_TOKEN +import kotlinx.serialization.json.internal.lexer.CharMappings.ESCAPE_2_CHAR +import kotlinx.serialization.json.internal.minify import kotlin.math.floor import kotlin.math.pow @@ -18,7 +19,7 @@ internal const val coerceInputValuesHint = internal const val specialFlowingValuesHint = "It is possible to deserialize them using 'JsonBuilder.allowSpecialFloatingPointValues = true'" internal const val ignoreUnknownKeysHint = - "Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys." + "Use 'ignoreUnknownKeys = true' in 'Json {}' builder or '@JsonIgnoreUnknownKeys' annotation to ignore unknown keys." internal const val allowStructuredMapKeysHint = "Use 'allowStructuredMapKeys = true' in 'Json {}' builder to convert such maps to [key1, value1, key2, value2,...] arrays." @@ -230,13 +231,17 @@ internal abstract class AbstractJsonLexer { fail(charToTokenClass(expected)) } - internal fun fail(expectedToken: Byte, wasConsumed: Boolean = true): Nothing { + internal inline fun fail( + expectedToken: Byte, + wasConsumed: Boolean = true, + message: (expected: String, source: String) -> String = { expected, source -> "Expected $expected, but had '$source' instead" } + ): Nothing { // Slow path, never called in normal code, can avoid optimizing it val expected = tokenDescription(expectedToken) val position = if (wasConsumed) currentPosition - 1 else currentPosition val s = if (currentPosition == source.length || position < 0) "EOF" else source[position].toString() - fail("Expected $expected, but had '$s' instead", position) + fail(message(expected, s), position) } open fun peekNextToken(): Byte { @@ -593,7 +598,10 @@ internal abstract class AbstractJsonLexer { // but still would like an error to point to the beginning of the key, so we are backtracking it val processed = substring(0, currentPosition) val lastIndexOf = processed.lastIndexOf(key) - fail("Encountered an unknown key '$key'", lastIndexOf, ignoreUnknownKeysHint) + throw JsonDecodingException( + "Encountered an unknown key '$key' at offset $lastIndexOf at path: ${path.getPath()}\n$ignoreUnknownKeysHint\n" + + "JSON input: ${source.minify(lastIndexOf)}" + ) } fun fail(message: String, position: Int = currentPosition, hint: String = ""): Nothing { @@ -698,6 +706,16 @@ internal abstract class AbstractJsonLexer { } } + fun consumeNumericLiteralFully(): Long { + val result = consumeNumericLiteral() + val next = consumeNextToken() + if (next != TC_EOF) { + fail(TC_EOF) { _, source -> "Expected input to contain a single valid number, but got '$source' after it" } + } + return result + } + + fun consumeBoolean(): Boolean { return consumeBoolean(skipWhitespaces()) } diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/CommentLexers.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/CommentLexers.kt similarity index 98% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/CommentLexers.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/CommentLexers.kt index f62c98db6..5ddf71e53 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/CommentLexers.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/CommentLexers.kt @@ -2,9 +2,9 @@ * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal.lexer +package kotlinx.serialization.json.internal.lexer -import dev.ragnarok.filegallery.util.serializeble.json.internal.InternalJsonReader +import kotlinx.serialization.json.internal.InternalJsonReader /* Implementations of these two classes are nearly identical. However, there are several reasons why it can't be unified diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/ReaderJsonLexer.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/ReaderJsonLexer.kt similarity index 96% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/ReaderJsonLexer.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/ReaderJsonLexer.kt index 5d8bffd5b..339afbf77 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/ReaderJsonLexer.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/ReaderJsonLexer.kt @@ -2,12 +2,12 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal.lexer +package kotlinx.serialization.json.internal.lexer -import dev.ragnarok.filegallery.util.serializeble.json.Json -import dev.ragnarok.filegallery.util.serializeble.json.internal.CharArrayPoolBatchSize -import dev.ragnarok.filegallery.util.serializeble.json.internal.InternalJsonReader import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.internal.CharArrayPoolBatchSize +import kotlinx.serialization.json.internal.InternalJsonReader internal const val BATCH_SIZE: Int = 16 * 1024 private const val DEFAULT_THRESHOLD = 128 diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/StringJsonLexer.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/StringJsonLexer.kt similarity index 97% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/StringJsonLexer.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/StringJsonLexer.kt index 9c0936811..666996d9d 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/json/internal/lexer/StringJsonLexer.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/json/internal/lexer/StringJsonLexer.kt @@ -2,10 +2,10 @@ * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package dev.ragnarok.filegallery.util.serializeble.json.internal.lexer +package kotlinx.serialization.json.internal.lexer -import dev.ragnarok.filegallery.util.serializeble.json.Json import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.Json @OptIn(ExperimentalSerializationApi::class) internal fun StringJsonLexer(json: Json, source: String) = diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPack.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPack.kt similarity index 87% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPack.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPack.kt index 03f2b20b3..50baffd14 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPack.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPack.kt @@ -1,16 +1,7 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack +package kotlinx.serialization.msgpack import dev.ragnarok.fenrir.module.BufferWriteNative import dev.ragnarok.fenrir.module.FenrirNative -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.msgpack.internal.BasicMsgPackDecoder -import dev.ragnarok.filegallery.util.serializeble.msgpack.internal.BasicMsgPackEncoder -import dev.ragnarok.filegallery.util.serializeble.msgpack.internal.InlineDecoderHelper -import dev.ragnarok.filegallery.util.serializeble.msgpack.internal.InlineEncoderHelper -import dev.ragnarok.filegallery.util.serializeble.msgpack.internal.MsgPackDecoder -import dev.ragnarok.filegallery.util.serializeble.msgpack.internal.MsgPackEncoder -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.toMsgPackArrayBuffer -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.toMsgPackBufferedSource import kotlinx.serialization.BinaryFormat import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi @@ -21,7 +12,16 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.buildClassSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonElement import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder +import kotlinx.serialization.msgpack.internal.BasicMsgPackEncoder +import kotlinx.serialization.msgpack.internal.InlineDecoderHelper +import kotlinx.serialization.msgpack.internal.InlineEncoderHelper +import kotlinx.serialization.msgpack.internal.MsgPackDecoder +import kotlinx.serialization.msgpack.internal.MsgPackEncoder +import kotlinx.serialization.msgpack.stream.toMsgPackArrayBuffer +import kotlinx.serialization.msgpack.stream.toMsgPackBufferedSource import kotlinx.serialization.serializer import okio.BufferedSource diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPackConfiguration.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackConfiguration.kt similarity index 96% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPackConfiguration.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackConfiguration.kt index c927b836a..39ce0c8c8 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPackConfiguration.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackConfiguration.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack +package kotlinx.serialization.msgpack /** * MsgPack configuration diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPackDynamicSerializer.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackDynamicSerializer.kt similarity index 93% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPackDynamicSerializer.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackDynamicSerializer.kt index b9992072c..81c1d4a61 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPackDynamicSerializer.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackDynamicSerializer.kt @@ -1,9 +1,5 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack +package kotlinx.serialization.msgpack -import dev.ragnarok.filegallery.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.filegallery.util.serializeble.msgpack.extensions.DynamicMsgPackExtensionSerializer -import dev.ragnarok.filegallery.util.serializeble.msgpack.internal.MsgPackTypeDecoder -import dev.ragnarok.filegallery.util.serializeble.msgpack.types.MsgPackType import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.ArraySerializer @@ -16,6 +12,10 @@ import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.buildSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.extensions.DynamicMsgPackExtensionSerializer +import kotlinx.serialization.msgpack.internal.MsgPackTypeDecoder +import kotlinx.serialization.msgpack.types.MsgPackType import kotlinx.serialization.serializer open class MsgPackDynamicSerializer( diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPackTreeReader.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackTreeReader.kt similarity index 91% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPackTreeReader.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackTreeReader.kt index d37c7a9fa..c66e93284 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/MsgPackTreeReader.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/MsgPackTreeReader.kt @@ -1,14 +1,14 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack - -import dev.ragnarok.filegallery.util.serializeble.json.JsonArray -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.json.JsonNull -import dev.ragnarok.filegallery.util.serializeble.json.JsonObject -import dev.ragnarok.filegallery.util.serializeble.json.JsonPrimitive -import dev.ragnarok.filegallery.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.filegallery.util.serializeble.msgpack.internal.BasicMsgPackDecoder -import dev.ragnarok.filegallery.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.filegallery.util.serializeble.msgpack.utils.joinToNumber +package kotlinx.serialization.msgpack + +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.joinToNumber internal class MsgPackTreeReader( private val basicMsgPackDecoder: BasicMsgPackDecoder diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/exceptions/MsgPackSerializationException.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/exceptions/MsgPackSerializationException.kt similarity index 90% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/exceptions/MsgPackSerializationException.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/exceptions/MsgPackSerializationException.kt index 1c3b81d95..4de19ce52 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/exceptions/MsgPackSerializationException.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/exceptions/MsgPackSerializationException.kt @@ -1,11 +1,11 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.exceptions +package kotlinx.serialization.msgpack.exceptions -import dev.ragnarok.filegallery.util.serializeble.msgpack.extensions.MsgPackExtension -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.MsgPackDataBuffer -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.MsgPackDataInputBuffer -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.MsgPackDataInputOkio -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.MsgPackDataOutputBuffer import kotlinx.serialization.SerializationException +import kotlinx.serialization.msgpack.extensions.MsgPackExtension +import kotlinx.serialization.msgpack.stream.MsgPackDataBuffer +import kotlinx.serialization.msgpack.stream.MsgPackDataInputBuffer +import kotlinx.serialization.msgpack.stream.MsgPackDataInputOkio +import kotlinx.serialization.msgpack.stream.MsgPackDataOutputBuffer private fun ByteArray.toHex() = this.joinToString(separator = "") { it.toHex() } private fun Byte.toHex() = toInt().and(0xff).toString(16).padStart(2, '0') diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/BaseMsgPackExtensionSerializer.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/BaseMsgPackExtensionSerializer.kt similarity index 89% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/BaseMsgPackExtensionSerializer.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/BaseMsgPackExtensionSerializer.kt index 0c96f4f46..f573f8349 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/BaseMsgPackExtensionSerializer.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/BaseMsgPackExtensionSerializer.kt @@ -1,10 +1,10 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.extensions +package kotlinx.serialization.msgpack.extensions -import dev.ragnarok.filegallery.util.serializeble.msgpack.exceptions.MsgPackSerializationException import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException abstract class BaseMsgPackExtensionSerializer : KSerializer { private val serializer = MsgPackExtension.serializer() diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt similarity index 96% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt index eb338b8f0..a4725435e 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/DynamicMsgPackExtensionSerializer.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.extensions +package kotlinx.serialization.msgpack.extensions import kotlinx.serialization.SerializationException import kotlin.reflect.KClass diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/MsgPackExtension.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackExtension.kt similarity index 80% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/MsgPackExtension.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackExtension.kt index 2ca057d43..f65fcc7bc 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/MsgPackExtension.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackExtension.kt @@ -1,7 +1,7 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.extensions +package kotlinx.serialization.msgpack.extensions -import dev.ragnarok.filegallery.util.serializeble.msgpack.types.MsgPackType import kotlinx.serialization.Serializable +import kotlinx.serialization.msgpack.types.MsgPackType @Serializable class MsgPackExtension( diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/MsgPackTimestampExtension.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackTimestampExtension.kt similarity index 93% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/MsgPackTimestampExtension.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackTimestampExtension.kt index bde4c78be..3e61abe8b 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/extensions/MsgPackTimestampExtension.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/extensions/MsgPackTimestampExtension.kt @@ -1,9 +1,9 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.extensions +package kotlinx.serialization.msgpack.extensions -import dev.ragnarok.filegallery.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.filegallery.util.serializeble.msgpack.utils.joinToNumber -import dev.ragnarok.filegallery.util.serializeble.msgpack.utils.splitToByteArray import kotlinx.serialization.Serializable +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.utils.joinToNumber +import kotlinx.serialization.msgpack.utils.splitToByteArray @Serializable(with = MsgPackTimestampExtensionSerializer::class) sealed class MsgPackTimestamp { diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgPackDecoder.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackDecoder.kt similarity index 93% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgPackDecoder.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackDecoder.kt index 770de0e72..93d1bb317 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgPackDecoder.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackDecoder.kt @@ -1,13 +1,5 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.internal - -import dev.ragnarok.filegallery.util.serializeble.json.JsonElement -import dev.ragnarok.filegallery.util.serializeble.msgpack.MsgPackConfiguration -import dev.ragnarok.filegallery.util.serializeble.msgpack.MsgPackNullableDynamicSerializer -import dev.ragnarok.filegallery.util.serializeble.msgpack.MsgPackTreeReader -import dev.ragnarok.filegallery.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.MsgPackDataInputBuffer -import dev.ragnarok.filegallery.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.filegallery.util.serializeble.msgpack.utils.joinToNumber +package kotlinx.serialization.msgpack.internal + import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.builtins.ByteArraySerializer import kotlinx.serialization.descriptors.SerialDescriptor @@ -15,7 +7,15 @@ import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.encoding.AbstractDecoder import kotlinx.serialization.encoding.CompositeDecoder import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.json.JsonElement import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.msgpack.MsgPackConfiguration +import kotlinx.serialization.msgpack.MsgPackNullableDynamicSerializer +import kotlinx.serialization.msgpack.MsgPackTreeReader +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.stream.MsgPackDataInputBuffer +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.joinToNumber interface MsgPackTypeDecoder { fun peekNextType(): Byte @@ -230,7 +230,7 @@ internal class BasicMsgPackDecoder( override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder { if (descriptor.kind in arrayOf(StructureKind.CLASS, StructureKind.OBJECT)) { - if (descriptor.serialName == "dev.ragnarok.filegallery.util.serializeble.msgpack.extensions.MsgPackExtension") { + if (descriptor.serialName == "kotlinx.serialization.msgpack.extensions.MsgPackExtension") { return ExtensionTypeDecoder(this) } diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgPackEncoder.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackEncoder.kt similarity index 93% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgPackEncoder.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackEncoder.kt index ca21c347e..3a31e6a36 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgPackEncoder.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPackEncoder.kt @@ -1,12 +1,5 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.internal - -import dev.ragnarok.filegallery.util.serializeble.msgpack.MsgPackConfiguration -import dev.ragnarok.filegallery.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.MsgPackDataOutputArrayBuffer -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.MsgPackDataOutputArrayBufferCompressed -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.MsgPackDataOutputBuffer -import dev.ragnarok.filegallery.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.filegallery.util.serializeble.msgpack.utils.splitToByteArray +package kotlinx.serialization.msgpack.internal + import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.builtins.ByteArraySerializer @@ -16,6 +9,13 @@ import kotlinx.serialization.encoding.AbstractEncoder import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.msgpack.MsgPackConfiguration +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.stream.MsgPackDataOutputArrayBuffer +import kotlinx.serialization.msgpack.stream.MsgPackDataOutputArrayBufferCompressed +import kotlinx.serialization.msgpack.stream.MsgPackDataOutputBuffer +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.splitToByteArray internal class BasicMsgPackEncoder( private val configuration: MsgPackConfiguration, @@ -98,7 +98,7 @@ internal class BasicMsgPackEncoder( override fun beginStructure(descriptor: SerialDescriptor): CompositeEncoder { return if (descriptor.kind in arrayOf(StructureKind.CLASS, StructureKind.OBJECT)) { - if (descriptor.serialName == "dev.ragnarok.filegallery.util.serializeble.msgpack.extensions.MsgPackExtension") { + if (descriptor.serialName == "kotlinx.serialization.msgpack.extensions.MsgPackExtension") { ExtensionTypeEncoder(this) } else { beginCollection(descriptor, descriptor.elementsCount) diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgPacker.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPacker.kt similarity index 94% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgPacker.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPacker.kt index c52e08f21..941003366 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgPacker.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgPacker.kt @@ -1,8 +1,8 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.internal +package kotlinx.serialization.msgpack.internal -import dev.ragnarok.filegallery.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.filegallery.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.filegallery.util.serializeble.msgpack.utils.splitToByteArray +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.splitToByteArray internal interface MsgPacker { fun packNull(): ByteArray diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgUnpacker.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgUnpacker.kt similarity index 96% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgUnpacker.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgUnpacker.kt index f1545ceab..6d1114776 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/internal/MsgUnpacker.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/internal/MsgUnpacker.kt @@ -1,9 +1,9 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.internal +package kotlinx.serialization.msgpack.internal -import dev.ragnarok.filegallery.util.serializeble.msgpack.exceptions.MsgPackSerializationException -import dev.ragnarok.filegallery.util.serializeble.msgpack.stream.MsgPackDataInputBuffer -import dev.ragnarok.filegallery.util.serializeble.msgpack.types.MsgPackType -import dev.ragnarok.filegallery.util.serializeble.msgpack.utils.joinToNumber +import kotlinx.serialization.msgpack.exceptions.MsgPackSerializationException +import kotlinx.serialization.msgpack.stream.MsgPackDataInputBuffer +import kotlinx.serialization.msgpack.types.MsgPackType +import kotlinx.serialization.msgpack.utils.joinToNumber internal interface MsgUnpacker { fun unpackNull() diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/stream/MsgPackDataBuffer.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/stream/MsgPackDataBuffer.kt similarity index 98% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/stream/MsgPackDataBuffer.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/stream/MsgPackDataBuffer.kt index b6881a2ab..9d27da12c 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/stream/MsgPackDataBuffer.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/stream/MsgPackDataBuffer.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.stream +package kotlinx.serialization.msgpack.stream import com.google.common.math.IntMath.mod import dev.ragnarok.fenrir.module.BufferWriteNative diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/types/MsgPackType.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/types/MsgPackType.kt similarity index 99% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/types/MsgPackType.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/types/MsgPackType.kt index 06f07106e..a38f9c201 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/types/MsgPackType.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/types/MsgPackType.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.types +package kotlinx.serialization.msgpack.types internal object MsgPackType { internal object Boolean { diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/utils/ByteArrayUtils.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/utils/ByteArrayUtils.kt similarity index 94% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/utils/ByteArrayUtils.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/utils/ByteArrayUtils.kt index 5880a2627..4d2033704 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/msgpack/utils/ByteArrayUtils.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/msgpack/utils/ByteArrayUtils.kt @@ -1,4 +1,4 @@ -package dev.ragnarok.filegallery.util.serializeble.msgpack.utils +package kotlinx.serialization.msgpack.utils internal inline fun T.splitToByteArray(): ByteArray { val byteCount = when (T::class) { diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/AsProperty.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/AsProperty.kt similarity index 97% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/AsProperty.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/AsProperty.kt index b9bdc013b..9792b92fc 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/AsProperty.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/AsProperty.kt @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.filegallery.util.serializeble.prefs +package kotlinx.serialization.prefs import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.nullable @@ -15,7 +15,7 @@ import kotlin.reflect.KProperty import android.content.* import kotlin.test.* import kotlinx.serialization.builtins.* -import dev.ragnarok.filegallery.util.serializeble.prefs.* +import kotlinx.serialization.prefs.* import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/Preferences.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/Preferences.kt similarity index 97% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/Preferences.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/Preferences.kt index b18cbe8d2..78f2859df 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/Preferences.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/Preferences.kt @@ -2,16 +2,16 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.filegallery.util.serializeble.prefs +package kotlinx.serialization.prefs import android.content.SharedPreferences -import dev.ragnarok.filegallery.util.serializeble.prefs.encoding.PreferenceDecoder -import dev.ragnarok.filegallery.util.serializeble.prefs.encoding.PreferenceEncoder import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerialFormat import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.modules.EmptySerializersModule import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.prefs.encoding.PreferenceDecoder +import kotlinx.serialization.prefs.encoding.PreferenceEncoder import kotlinx.serialization.serializer import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind @@ -22,7 +22,7 @@ import kotlin.contracts.contract import android.content.* import kotlin.test.* import kotlinx.serialization.* -import dev.ragnarok.filegallery.util.serializeble.prefs.* +import kotlinx.serialization.prefs.* import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/encoding/Helpers.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/encoding/Helpers.kt similarity index 90% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/encoding/Helpers.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/encoding/Helpers.kt index 3a4331f23..4451907f7 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/encoding/Helpers.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/encoding/Helpers.kt @@ -2,9 +2,8 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.filegallery.util.serializeble.prefs.encoding +package kotlinx.serialization.prefs.encoding -import dev.ragnarok.filegallery.util.serializeble.prefs.PreferenceConfiguration import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException import kotlinx.serialization.descriptors.PrimitiveKind @@ -12,6 +11,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialKind import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.encoding.CompositeDecoder +import kotlinx.serialization.prefs.PreferenceConfiguration @OptIn(ExperimentalSerializationApi::class) internal fun PreferenceConfiguration.shouldSerializeStringSet(descriptor: SerialDescriptor): Boolean { diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/encoding/PreferenceDecoder.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceDecoder.kt similarity index 96% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/encoding/PreferenceDecoder.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceDecoder.kt index 4a65d601e..6de8dc171 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/encoding/PreferenceDecoder.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceDecoder.kt @@ -2,11 +2,9 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.filegallery.util.serializeble.prefs.encoding +package kotlinx.serialization.prefs.encoding import android.content.SharedPreferences -import dev.ragnarok.filegallery.util.serializeble.prefs.DoubleRepresentation -import dev.ragnarok.filegallery.util.serializeble.prefs.Preferences import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.SerializationException @@ -16,6 +14,8 @@ import kotlinx.serialization.encoding.AbstractDecoder import kotlinx.serialization.encoding.CompositeDecoder import kotlinx.serialization.internal.NamedValueDecoder import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.prefs.DoubleRepresentation +import kotlinx.serialization.prefs.Preferences @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class) @Suppress("TooManyFunctions") diff --git a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/encoding/PreferenceEncoder.kt b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceEncoder.kt similarity index 96% rename from app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/encoding/PreferenceEncoder.kt rename to app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceEncoder.kt index 3a01d61d7..2524fab5c 100644 --- a/app_filegallery/src/main/kotlin/dev/ragnarok/filegallery/util/serializeble/prefs/encoding/PreferenceEncoder.kt +++ b/app_filegallery/src/main/kotlin/kotlinx/serialization/prefs/encoding/PreferenceEncoder.kt @@ -2,11 +2,9 @@ // // SPDX-License-Identifier: Apache-2.0 -package dev.ragnarok.filegallery.util.serializeble.prefs.encoding +package kotlinx.serialization.prefs.encoding import android.content.SharedPreferences -import dev.ragnarok.filegallery.util.serializeble.prefs.DoubleRepresentation -import dev.ragnarok.filegallery.util.serializeble.prefs.Preferences import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.SerializationException @@ -16,6 +14,8 @@ import kotlinx.serialization.encoding.AbstractEncoder import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.internal.NamedValueEncoder import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.prefs.DoubleRepresentation +import kotlinx.serialization.prefs.Preferences @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class) @Suppress("TooManyFunctions") diff --git a/build.gradle b/build.gradle index ce57bb856..b3d671403 100644 --- a/build.gradle +++ b/build.gradle @@ -13,13 +13,13 @@ buildscript { ext.appFileGalleryVersionName = "1.999" //androidx libraries - ext.activityVersion = "1.10.0-beta01" + ext.activityVersion = "1.10.0-rc01" ext.annotationVersion = "1.9.1" ext.appcompatVersion = "1.7.0" ext.biometricVersion = "1.4.0-alpha02" ext.browserVersion = "1.8.0" ext.cardviewVersion = "1.0.0" - ext.collectionVersion = "1.5.0-alpha06" + ext.collectionVersion = "1.5.0-beta01" ext.concurentVersion = "1.2.0" ext.constraintlayoutVersion = "2.2.0" ext.coordinatorlayoutVersion = "1.3.0-alpha02" @@ -32,11 +32,11 @@ buildscript { ext.exifinterfaceVersion = "1.4.0-alpha01" ext.fragmentVersion = "1.8.5" ext.graphicsShapesVersion = "1.0.1" - ext.lifecycleVersion = "2.8.7" + ext.lifecycleVersion = "2.9.0-alpha08" ext.mediaVersion = "1.7.0" ext.media3Version = "1.5.0" ext.resourceInspectionAnnotation = "1.0.1" - ext.savedStateVersion = "1.3.0-alpha05" + ext.savedStateVersion = "1.3.0-alpha06" ext.swiperefreshlayoutVersion = "1.2.0-alpha01" ext.tracingVersion = "1.2.0" ext.transitionVersion = "1.5.1" @@ -60,14 +60,14 @@ buildscript { //common libraries ext.kotlin_version = "2.1.0" ext.kotlin_coroutines = "1.9.0" - ext.kotlin_serializer = "1.7.3" + ext.kotlin_serializer = "1.8.0-RC" ext.okhttpLibraryVersion = "5.0.0-SNAPSHOT" //ext.okhttpLibraryVersion = "5.0.0-alpha.14" ext.okioVersion = "3.9.1" ext.guavaVersion = "33.3.1-android" ext.errorProneVersion = "2.36.0" ext.checkerCompatQualVersion = "2.5.6" - ext.checkerQualAndroidVersion = "3.48.2" + ext.checkerQualAndroidVersion = "3.48.3" //APP_PROPS ext.targetAbi = is_developer_build ? ["arm64-v8a", "x86_64"] : ["arm64-v8a", "armeabi-v7a", "x86_64"] diff --git a/camera2/build.gradle b/camera2/build.gradle index e1a76556d..d24f309b6 100644 --- a/camera2/build.gradle +++ b/camera2/build.gradle @@ -3,7 +3,7 @@ plugins { id("kotlin-android") } -//1.4.0 +//1.4.1 android { namespace "androidx.camera" diff --git a/camera2/src/main/java/androidx/camera/camera2/internal/CaptureSession.java b/camera2/src/main/java/androidx/camera/camera2/internal/CaptureSession.java index 70d6935a5..3c8df148b 100644 --- a/camera2/src/main/java/androidx/camera/camera2/internal/CaptureSession.java +++ b/camera2/src/main/java/androidx/camera/camera2/internal/CaptureSession.java @@ -16,6 +16,8 @@ package androidx.camera.camera2.internal; +import android.annotation.SuppressLint; +import android.graphics.ImageFormat; import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraCaptureSession; import android.hardware.camera2.CameraCaptureSession.CaptureCallback; @@ -23,6 +25,7 @@ import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.TotalCaptureResult; import android.hardware.camera2.params.DynamicRangeProfiles; +import android.hardware.camera2.params.MultiResolutionStreamInfo; import android.hardware.camera2.params.OutputConfiguration; import android.os.Build; import android.view.Surface; @@ -31,6 +34,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.OptIn; +import androidx.annotation.RequiresApi; import androidx.camera.camera2.impl.Camera2ImplConfig; import androidx.camera.camera2.internal.compat.params.DynamicRangeConversions; import androidx.camera.camera2.internal.compat.params.DynamicRangesCompat; @@ -51,6 +55,7 @@ import androidx.camera.core.impl.DeferrableSurface; import androidx.camera.core.impl.Quirks; import androidx.camera.core.impl.SessionConfig; +import androidx.camera.core.impl.utils.SurfaceUtil; import androidx.camera.core.impl.utils.executor.CameraXExecutors; import androidx.camera.core.impl.utils.futures.FutureCallback; import androidx.camera.core.impl.utils.futures.FutureChain; @@ -60,11 +65,15 @@ import com.google.common.util.concurrent.ListenableFuture; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.CancellationException; /** @@ -123,24 +132,43 @@ final class CaptureSession implements CaptureSessionInterface { private final RequestMonitor mRequestMonitor; private final DynamicRangesCompat mDynamicRangesCompat; private final TemplateParamsOverride mTemplateParamsOverride; + private final boolean mCanUseMultiResolutionImageReader; /** * Constructor for CaptureSession without CameraQuirk. */ CaptureSession(@NonNull DynamicRangesCompat dynamicRangesCompat) { - this(dynamicRangesCompat, new Quirks(Collections.emptyList())); + this(dynamicRangesCompat, false); } /** - * Constructor for CaptureSession. + * Constructor for CaptureSession without CameraQuirk. + */ + CaptureSession(@NonNull DynamicRangesCompat dynamicRangesCompat, + boolean canUseMultiResolutionImageReader) { + this(dynamicRangesCompat, new Quirks(Collections.emptyList()), + canUseMultiResolutionImageReader); + } + + /** + * Constructor for CaptureSession with CameraQuirk. */ CaptureSession(@NonNull DynamicRangesCompat dynamicRangesCompat, @NonNull Quirks cameraQuirks) { + this(dynamicRangesCompat, cameraQuirks, false); + } + + /** + * Constructor for CaptureSession. + */ + CaptureSession(@NonNull DynamicRangesCompat dynamicRangesCompat, + @NonNull Quirks cameraQuirks, boolean canUseMultiResolutionImageReader) { mState = State.INITIALIZED; mDynamicRangesCompat = dynamicRangesCompat; mCaptureSessionStateCallback = new StateCallback(); mRequestMonitor = new RequestMonitor(cameraQuirks.contains(CaptureNoResponseQuirk.class)); mTemplateParamsOverride = new TemplateParamsOverride(cameraQuirks); + mCanUseMultiResolutionImageReader = canUseMultiResolutionImageReader; } @Override @@ -300,19 +328,41 @@ private ListenableFuture openCaptureSession(@NonNull List configu CaptureConfig.Builder sessionParameterConfigBuilder = CaptureConfig.Builder.from(sessionConfig.getRepeatingCaptureConfig()); + Map + mrirOutputConfigurationCompatMap = new HashMap<>(); + if (mCanUseMultiResolutionImageReader && Build.VERSION.SDK_INT >= 35) { + Map> groupIdToOutputConfigsMap = + groupMrirOutputConfigs(sessionConfig.getOutputConfigs()); + mrirOutputConfigurationCompatMap = + createMultiResolutionOutputConfigurationCompats( + groupIdToOutputConfigsMap, mConfiguredSurfaceMap); + } + List outputConfigList = new ArrayList<>(); String physicalCameraIdForAllStreams = camera2Config.getPhysicalCameraId(null); for (SessionConfig.OutputConfig outputConfig : sessionConfig.getOutputConfigs()) { - OutputConfigurationCompat outputConfiguration = - getOutputConfigurationCompat( - outputConfig, - mConfiguredSurfaceMap, - physicalCameraIdForAllStreams); - if (mStreamUseCaseMap.containsKey(outputConfig.getSurface())) { - outputConfiguration.setStreamUseCase( - mStreamUseCaseMap.get(outputConfig.getSurface())); + OutputConfigurationCompat outputConfiguration = null; + + // If an OutputConfiguration has been created via the MRIR approach, + // retrieves it from the map + if (mCanUseMultiResolutionImageReader && Build.VERSION.SDK_INT >= 35) { + outputConfiguration = mrirOutputConfigurationCompatMap.get( + outputConfig); + } + + // Otherwise, uses the original approach to create the + // OutputConfigurationCompat. + if (outputConfiguration == null) { + outputConfiguration = getOutputConfigurationCompat( + outputConfig, + mConfiguredSurfaceMap, + physicalCameraIdForAllStreams); + if (mStreamUseCaseMap.containsKey(outputConfig.getSurface())) { + outputConfiguration.setStreamUseCase( + mStreamUseCaseMap.get(outputConfig.getSurface())); + } } outputConfigList.add(outputConfiguration); } @@ -899,6 +949,110 @@ private CameraCaptureSession.CaptureCallback createCamera2CaptureCallback( return Camera2CaptureCallbacks.createComboCallback(camera2Callbacks); } + /** + * Returns the map which contains the data by mapping surface group id to OutputConfig list. + */ + @NonNull + private static Map> groupMrirOutputConfigs( + @NonNull Collection outputConfigs) { + Map> groupResult = new HashMap<>(); + + for (SessionConfig.OutputConfig outputConfig : outputConfigs) { + // When shared surfaces is not empty, surface sharing will be enabled on the + // OutputConfiguration. In that case, MultiResolutionImageReader shouldn't be used. + if (outputConfig.getSurfaceGroupId() <= 0 + || !outputConfig.getSharedSurfaces().isEmpty()) { + continue; + } + List groupedOutputConfigs = groupResult.get( + outputConfig.getSurfaceGroupId()); + if (groupedOutputConfigs == null) { + groupedOutputConfigs = new ArrayList<>(); + groupResult.put(outputConfig.getSurfaceGroupId(), groupedOutputConfigs); + } + groupedOutputConfigs.add(outputConfig); + } + + // Double-check that the list size of each group is at least 2. It is the necessary + // condition to create a MRIR. + Map> mrirGroupResult = new HashMap<>(); + for (int groupId : groupResult.keySet()) { + if (groupResult.get(groupId).size() >= 2) { + mrirGroupResult.put(groupId, groupResult.get(groupId)); + } + } + + return mrirGroupResult; + } + + @NonNull + @RequiresApi(35) + private static Map + createMultiResolutionOutputConfigurationCompats( + @NonNull Map> groupIdToOutputConfigsMap, + @NonNull Map configuredSurfaceMap) { + Map + outputConfigToOutputConfigurationCompatMap = new HashMap<>(); + + for (int groupId : groupIdToOutputConfigsMap.keySet()) { + List streamInfos = new ArrayList<>(); + int imageFormat = ImageFormat.UNKNOWN; + for (SessionConfig.OutputConfig outputConfig : groupIdToOutputConfigsMap.get(groupId)) { + Surface surface = configuredSurfaceMap.get(outputConfig.getSurface()); + SurfaceUtil.SurfaceInfo surfaceInfo = SurfaceUtil.getSurfaceInfo(surface); + if (imageFormat == ImageFormat.UNKNOWN) { + imageFormat = surfaceInfo.format; + } + streamInfos.add(new MultiResolutionStreamInfo(surfaceInfo.width, surfaceInfo.height, + Objects.requireNonNull(outputConfig.getPhysicalCameraId()))); + } + if (imageFormat == ImageFormat.UNKNOWN || streamInfos.isEmpty()) { + Logger.e(TAG, "Skips to create instances for multi-resolution output. imageFormat: " + + imageFormat + ", streamInfos size: " + streamInfos.size()); + continue; + } + List outputConfigurations = + createInstancesForMultiResolutionOutput(streamInfos, imageFormat); + if (outputConfigurations != null) { + for (SessionConfig.OutputConfig outputConfig : groupIdToOutputConfigsMap.get( + groupId)) { + OutputConfiguration outputConfiguration = outputConfigurations.remove(0); + Surface surface = configuredSurfaceMap.get(outputConfig.getSurface()); + outputConfiguration.addSurface(surface); + outputConfigToOutputConfigurationCompatMap.put(outputConfig, + new OutputConfigurationCompat(outputConfiguration)); + } + } + } + return outputConfigToOutputConfigurationCompatMap; + } + + /** + * Use java reflection to access the API so that we don't need to upgrade compileSdk as 35 in + * the release branch. When this method is invoked, the API has become public on the device. It + * won't cause the problem about accessing the non-SDK API. + */ + /** @noinspection unchecked */ + @SuppressLint("BanUncheckedReflection") + @SuppressWarnings("unchecked") + @RequiresApi(35) + @Nullable + private static List createInstancesForMultiResolutionOutput( + @NonNull List streamInfos, int format) { + // TODO(b/376185185): Invoke the API directly after the androidx code base upgrades to + // compile by API 35 SDK. + try { + Method createInstanceMethod = OutputConfiguration.class.getMethod( + "createInstancesForMultiResolutionOutput", Collection.class, int.class); + return (List) createInstanceMethod.invoke(null, streamInfos, + format); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + Logger.e(TAG, + "Failed to create instances for multi-resolution output, " + e.getMessage()); + return null; + } + } + enum State { /** The default state of the session before construction. */ UNINITIALIZED, diff --git a/camera2/src/main/java/androidx/camera/camera2/internal/ProcessingCaptureSession.java b/camera2/src/main/java/androidx/camera/camera2/internal/ProcessingCaptureSession.java index 3bda6a1b3..13da23cc6 100644 --- a/camera2/src/main/java/androidx/camera/camera2/internal/ProcessingCaptureSession.java +++ b/camera2/src/main/java/androidx/camera/camera2/internal/ProcessingCaptureSession.java @@ -24,6 +24,8 @@ import androidx.annotation.OptIn; import androidx.camera.camera2.impl.Camera2ImplConfig; import androidx.camera.camera2.internal.compat.params.DynamicRangesCompat; +import androidx.camera.camera2.internal.compat.quirk.CaptureSessionShouldUseMrirQuirk; +import androidx.camera.camera2.internal.compat.quirk.DeviceQuirks; import androidx.camera.camera2.interop.CaptureRequestOptions; import androidx.camera.camera2.interop.ExperimentalCamera2Interop; import androidx.camera.core.ImageAnalysis; @@ -124,7 +126,8 @@ private enum ProcessorState { @NonNull Camera2CameraInfoImpl camera2CameraInfoImpl, @NonNull DynamicRangesCompat dynamicRangesCompat, @NonNull Executor executor, @NonNull ScheduledExecutorService scheduledExecutorService) { - mCaptureSession = new CaptureSession(dynamicRangesCompat); + mCaptureSession = new CaptureSession(dynamicRangesCompat, + DeviceQuirks.get(CaptureSessionShouldUseMrirQuirk.class) != null); mSessionProcessor = sessionProcessor; mCamera2CameraInfoImpl = camera2CameraInfoImpl; mExecutor = executor; @@ -382,7 +385,7 @@ public void issueCaptureRequests(@NonNull List captureConfigs) { break; case ON_CAPTURE_SESSION_STARTED: for (CaptureConfig captureConfig : captureConfigs) { - if (captureConfig.getTemplateType() == CameraDevice.TEMPLATE_STILL_CAPTURE) { + if (isTemplateTypeForStillCapture(captureConfig.getTemplateType())) { issueStillCaptureRequest(captureConfig); } else { issueTriggerRequest(captureConfig); @@ -397,6 +400,12 @@ public void issueCaptureRequests(@NonNull List captureConfigs) { break; } } + + private boolean isTemplateTypeForStillCapture(int templateType) { + return templateType == CameraDevice.TEMPLATE_STILL_CAPTURE + || templateType == CameraDevice.TEMPLATE_VIDEO_SNAPSHOT; + } + void issueStillCaptureRequest(@NonNull CaptureConfig captureConfig) { CaptureRequestOptions.Builder builder = CaptureRequestOptions.Builder.from( diff --git a/camera2/src/main/java/androidx/camera/camera2/internal/compat/params/OutputConfigurationCompat.java b/camera2/src/main/java/androidx/camera/camera2/internal/compat/params/OutputConfigurationCompat.java index 6357854c9..97ebe9462 100644 --- a/camera2/src/main/java/androidx/camera/camera2/internal/compat/params/OutputConfigurationCompat.java +++ b/camera2/src/main/java/androidx/camera/camera2/internal/compat/params/OutputConfigurationCompat.java @@ -115,6 +115,11 @@ public OutputConfigurationCompat(@NonNull Size surfaceSize, @NonNull ClassQuirkSummary + * Bug Id: 376185185 + * Description: NIGHT mode extensions support on Google Pixel Android 15 or above devices need + * to create the {@link OutputConfiguration}s with multi-resolution output enabled. + * Otherwise, it will fail to capture still images until the camera focused on a + * nearby object. + * Device(s): Google Pixel Android 15 or above devices. + */ +public class CaptureSessionShouldUseMrirQuirk implements Quirk { + + static boolean load() { + return "google".equalsIgnoreCase(Build.BRAND) && Build.VERSION.SDK_INT >= 35; + } +} diff --git a/camera2/src/main/java/androidx/camera/camera2/internal/compat/quirk/DeviceQuirksLoader.java b/camera2/src/main/java/androidx/camera/camera2/internal/compat/quirk/DeviceQuirksLoader.java index 472007be2..9cb2e0f56 100644 --- a/camera2/src/main/java/androidx/camera/camera2/internal/compat/quirk/DeviceQuirksLoader.java +++ b/camera2/src/main/java/androidx/camera/camera2/internal/compat/quirk/DeviceQuirksLoader.java @@ -130,6 +130,11 @@ static List loadQuirks(@NonNull QuirkSettings quirkSettings) { SmallDisplaySizeQuirk.load())) { quirks.add(new SmallDisplaySizeQuirk()); } + if (quirkSettings.shouldEnableQuirk( + CaptureSessionShouldUseMrirQuirk.class, + CaptureSessionShouldUseMrirQuirk.load())) { + quirks.add(new CaptureSessionShouldUseMrirQuirk()); + } return quirks; } diff --git a/camera2/src/main/java/androidx/camera/core/impl/utils/SurfaceUtil.java b/camera2/src/main/java/androidx/camera/core/impl/utils/SurfaceUtil.java new file mode 100644 index 000000000..f4a38987d --- /dev/null +++ b/camera2/src/main/java/androidx/camera/core/impl/utils/SurfaceUtil.java @@ -0,0 +1,68 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package androidx.camera.core.impl.utils; + +import android.graphics.ImageFormat; +import android.view.Surface; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class SurfaceUtil { + private static final String TAG = "SurfaceUtil"; + public static final String JNI_LIB_NAME = "surface_util_jni"; + + static { + System.loadLibrary(JNI_LIB_NAME); + } + + private SurfaceUtil() { + } + + /** + * A class to store surface related information. + */ + public static class SurfaceInfo { + /** + * The surface format. + */ + public int format = ImageFormat.UNKNOWN; + /** + * The surface width; + */ + public int width = 0; + /** + * The surface height. + */ + public int height = 0; + } + + /** + * Returns the surface pixel format. + */ + @NonNull + public static SurfaceInfo getSurfaceInfo(@NonNull Surface surface) { + int[] surfaceInfoArray = nativeGetSurfaceInfo(surface); + SurfaceInfo surfaceInfo = new SurfaceInfo(); + surfaceInfo.format = surfaceInfoArray[0]; + surfaceInfo.width = surfaceInfoArray[1]; + surfaceInfo.height = surfaceInfoArray[2]; + return surfaceInfo; + } + + private static native int[] nativeGetSurfaceInfo(@Nullable Surface surface); +} diff --git a/libfenrir/src/main/jni/animation/thorvg/inc/thorvg.h b/libfenrir/src/main/jni/animation/thorvg/inc/thorvg.h index 7cb0ec4e8..9eb2b87dd 100644 --- a/libfenrir/src/main/jni/animation/thorvg/inc/thorvg.h +++ b/libfenrir/src/main/jni/animation/thorvg/inc/thorvg.h @@ -228,7 +228,8 @@ enum class SceneEffect : uint8_t { ClearAll = 0, ///< Reset all previously applied scene effects, restoring the scene to its original state. GaussianBlur, ///< Apply a blur effect with a Gaussian filter. Param(3) = {sigma(float)[> 0], direction(int)[both: 0 / horizontal: 1 / vertical: 2], border(int)[duplicate: 0 / wrap: 1], quality(int)[0 - 100]} - DropShadow ///< Apply a drop shadow effect with a Gaussian Blur filter. Param(8) = {color_R(int)[0 - 255], color_G(int)[0 - 255], color_B(int)[0 - 255], opacity(int)[0 - 255], angle(float)[0 - 360], distance(float), blur_sigma(float)[> 0], quality(int)[0 - 100]} + DropShadow, ///< Apply a drop shadow effect with a Gaussian Blur filter. Param(8) = {color_R(int)[0 - 255], color_G(int)[0 - 255], color_B(int)[0 - 255], opacity(int)[0 - 255], angle(float)[0 - 360], distance(float), blur_sigma(float)[> 0], quality(int)[0 - 100]} + Fill ///< Override the scene content color with a given fill information (Experimental API). Param(5) = {color_R(int)[0 - 255], color_G(int)[0 - 255], color_B(int)[0 - 255], opacity(int)[0 - 255]} }; @@ -644,7 +645,7 @@ class TVG_API Canvas * * @warning Please avoid accessing the paints during Canvas update/draw. You can access them after calling sync(). * @see Canvas::push() - * @see Canvas::clear() + * @see Canvas::remove() * * @warning This is read-only. Do not modify the list. * @note 1.0 @@ -669,25 +670,10 @@ class TVG_API Canvas * @note The rendering order of the paints is the same as the order as they were pushed. Consider sorting the paints before pushing them if you intend to use layering. * * @see Canvas::paints() - * @see Canvas::clear() + * @see Canvas::remove() */ Result push(Paint* target, Paint* at = nullptr) noexcept; - /** - * @brief Clear the internal canvas resources that used for the drawing. - * - * This API sets the total number of paints pushed into the canvas to zero. - * Depending on the value of the @p paints argument, the paints are either freed or retained. - * So if you need to update paint properties while maintaining the existing scene structure, you can set @p paints = false. - * - * @param[in] paints If @c true, the memory occupied by paints is deallocated; otherwise, the paints will be retained on the canvas. - * @param[in] buffer If @c true, the canvas target buffer is cleared with a zero value. - * - * @see Canvas::push() - * @see Canvas::paints() - */ - Result clear(bool paints = true, bool buffer = true) noexcept; - /** * @brief Removes a paint object or all paint objects from the root scene. * @@ -718,12 +704,18 @@ class TVG_API Canvas Result update(Paint* paint = nullptr) noexcept; /** - * @brief Requests the canvas to draw the Paint objects. + * @brief Requests the canvas to render Paint objects. + * + * @param[in] clear If @c true, clears the target buffer to zero before drawing. + * + * @note Clearing the buffer is unnecessary if the canvas will be fully covered + * with opaque content, which can improve performance. + * @note Drawing may be asynchronous if the thread count is greater than zero. + * To ensure drawing is complete, call sync() afterwards. * - * @note Drawing can be asynchronous if the assigned thread number is greater than zero. To guarantee the drawing is done, call sync() afterwards. * @see Canvas::sync() */ - Result draw() noexcept; + Result draw(bool clear = false) noexcept; /** * @brief Sets the drawing region in the canvas. diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieBuilder.cpp b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieBuilder.cpp index 7211b2008..062c06502 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieBuilder.cpp @@ -1314,14 +1314,20 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo) for (auto ef = layer->effects.begin(); ef < layer->effects.end(); ++ef) { if (!(*ef)->enable) continue; switch ((*ef)->type) { + case LottieEffect::Fill: { + auto effect = static_cast(*ef); + auto color = effect->color(frameNo); + layer->scene->push(SceneEffect::Fill, color.rgb[0], color.rgb[1], color.rgb[2], (int)(255.0f *effect->opacity(frameNo))); + break; + } case LottieEffect::DropShadow: { - auto effect = static_cast(*ef); + auto effect = static_cast(*ef); auto color = effect->color(frameNo); layer->scene->push(SceneEffect::DropShadow, color.rgb[0], color.rgb[1], color.rgb[2], (int)effect->opacity(frameNo), effect->angle(frameNo), effect->distance(frameNo), effect->blurness(frameNo) * BLUR_TO_SIGMA, QUALITY); break; } case LottieEffect::GaussianBlur: { - auto effect = static_cast(*ef); + auto effect = static_cast(*ef); layer->scene->push(SceneEffect::GaussianBlur, effect->blurness(frameNo) * BLUR_TO_SIGMA, effect->direction(frameNo) - 1, effect->wrap(frameNo), QUALITY); break; } diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieCommon.h b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieData.h similarity index 100% rename from libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieCommon.h rename to libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieData.h diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieExpressions.cpp b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieExpressions.cpp index bae380d74..f4e06d466 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieExpressions.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieExpressions.cpp @@ -238,7 +238,7 @@ static jerry_value_t _buildTrimpath(LottieTrimpath* trimpath, float frameNo) jerry_object_set_sz(obj, "end", end); jerry_value_free(end); auto offset = jerry_number(trimpath->offset(frameNo)); - jerry_object_set_sz(obj, "offset", offset); + jerry_object_set_sz(obj, EXP_OFFSET, offset); jerry_value_free(offset); return obj; diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieExpressions.h b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieExpressions.h index 4a3c2dcfd..724155466 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieExpressions.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieExpressions.h @@ -24,7 +24,7 @@ #define _TVG_LOTTIE_EXPRESSIONS_H_ #include "tvgCommon.h" -#include "tvgLottieCommon.h" +#include "tvgLottieData.h" struct LottieExpression; struct LottieComposition; diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieLoader.cpp b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieLoader.cpp index 116dd24d7..38e9c2318 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieLoader.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieLoader.cpp @@ -319,7 +319,7 @@ bool LottieLoader::override(const char* slots, bool byDefault) if (parser.apply(*s, byDefault)) succeed = applied = true; break; } - if (!applied) parser.skip(sid); + if (!applied) parser.skip(); ++idx; } free((char*)temp); diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieModel.h b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieModel.h index 130323ffb..72d2f245c 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieModel.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieModel.h @@ -83,6 +83,7 @@ struct LottieEffect { DropShadow = 0, GaussianBlur = 1, + Fill = 2, }; virtual ~LottieEffect() {} @@ -92,28 +93,45 @@ struct LottieEffect }; -struct LottieDropShadow : LottieEffect +struct LottieFxFill : LottieEffect { + //LottieFloat fillMask? + //LottieDropDown allMask? LottieColor color; - LottieFloat opacity = 0; + //LottieDropDown inverted + //LottieSlider horizontalFeather + //LottieSlider verticalFeather + LottieSlider opacity = 0; + + LottieFxFill() + { + type = Fill; + } +}; + + +struct LottieFxDropShadow : LottieEffect +{ + LottieColor color; + LottieSlider opacity = 0; LottieAngle angle = 0.0f; LottieSlider distance = 0.0f; LottieSlider blurness = 0.0f; - LottieDropShadow() + LottieFxDropShadow() { type = DropShadow; } }; -struct LottieGaussianBlur : LottieEffect +struct LottieFxGaussianBlur : LottieEffect { LottieSlider blurness = 0.0f; LottieCheckbox direction = 0; LottieCheckbox wrap = 0; - LottieGaussianBlur() + LottieFxGaussianBlur() { type = GaussianBlur; } @@ -764,15 +782,7 @@ struct LottieLayer : LottieGroup ~LottieLayer(); - uint8_t opacity(float frameNo) - { - //return zero if the visibility is false. - if (type == Null) return 255; - return transform->opacity(frameNo); - } - bool mergeable() override { return false; } - void prepare(RGB24* color = nullptr); float remap(LottieComposition* comp, float frameNo, LottieExpressions* exp); diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParser.cpp b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParser.cpp index dd5421228..94dd9abeb 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParser.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParser.cpp @@ -60,8 +60,9 @@ static unsigned long _int2str(int num) LottieEffect* LottieParser::getEffect(int type) { switch (type) { - case 25: return new LottieDropShadow; - case 29: return new LottieGaussianBlur; + case 21: return new LottieFxFill; + case 25: return new LottieFxDropShadow; + case 29: return new LottieFxGaussianBlur; default: return nullptr; } } @@ -176,7 +177,7 @@ bool LottieParser::getValue(TextDocument& doc) else if (KEY_AS("sc")) getValue(doc.stroke.color); else if (KEY_AS("sw")) doc.stroke.width = getFloat(); else if (KEY_AS("of")) doc.stroke.render = getBool(); - else skip(key); + else skip(); } return false; } @@ -198,7 +199,7 @@ bool LottieParser::getValue(PathSet& path) else if (KEY_AS("o")) getValue(outs); else if (KEY_AS("v")) getValue(pts); else if (KEY_AS("c")) closed = getBool(); - else skip(key); + else skip(); } //exit properly from the array @@ -381,7 +382,7 @@ void LottieParser::parseSlotProperty(T& prop) { while (auto key = nextObjectKey()) { if (KEY_AS("p")) parseProperty(prop); - else skip(key); + else skip(); } } @@ -455,7 +456,7 @@ void LottieParser::parseKeyFrame(T& prop) enterArray(); while (nextArrayValue()) { if (!interpolatorKey) interpolatorKey = getString(); - else skip(nullptr); + else skip(); } } } else if (KEY_AS("t")) { @@ -471,7 +472,7 @@ void LottieParser::parseKeyFrame(T& prop) continue; } else if (KEY_AS("h")) { frame.hold = getInt(); - } else skip(key); + } else skip(); } if (interpolator) { @@ -519,7 +520,7 @@ void LottieParser::parseProperty(T& prop, LottieObject* obj) else if (obj && KEY_AS("sid")) registerSlot(obj, getString()); else if (KEY_AS("x")) prop.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &prop); else if (KEY_AS("ix")) prop.ix = getInt(); - else skip(key); + else skip(); } prop.type = type; } @@ -561,7 +562,7 @@ LottieRect* LottieParser::parseRect() else if (KEY_AS("p")) parseProperty(rect->position); else if (KEY_AS("r")) parseProperty(rect->radius); else if (parseDirection(rect, key)) continue; - else skip(key); + else skip(); } return rect; } @@ -578,7 +579,7 @@ LottieEllipse* LottieParser::parseEllipse() else if (KEY_AS("p")) parseProperty(ellipse->position); else if (KEY_AS("s")) parseProperty(ellipse->size); else if (parseDirection(ellipse, key)) continue; - else skip(key); + else skip(); } return ellipse; } @@ -607,7 +608,7 @@ LottieTransform* LottieParser::parseTransform(bool ddd) else if (transform->coords && KEY_AS("x")) parseProperty(transform->coords->x); else if (transform->coords && KEY_AS("y")) parseProperty(transform->coords->y); else if (KEY_AS("x")) transform->position.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &transform->position); - else skip(key); + else skip(); } transform->position.type = LottieProperty::Type::Position; } @@ -620,7 +621,7 @@ LottieTransform* LottieParser::parseTransform(bool ddd) else if (transform->rotationEx && KEY_AS("rz")) parseProperty(transform->rotation); else if (KEY_AS("sk")) parseProperty(transform->skewAngle); else if (KEY_AS("sa")) parseProperty(transform->skewAxis); - else skip(key); + else skip(); } return transform; } @@ -638,7 +639,7 @@ LottieSolidFill* LottieParser::parseSolidFill() else if (KEY_AS("o")) parseProperty(fill->opacity, fill); else if (KEY_AS("fillEnabled")) fill->hidden |= !getBool(); else if (KEY_AS("r")) fill->rule = getFillRule(); - else skip(key); + else skip(); } return fill; } @@ -658,7 +659,7 @@ void LottieParser::parseStrokeDash(LottieStroke* stroke) else if (!strcmp("g", style)) idx = 2; //gap } else if (KEY_AS("v")) { parseProperty(stroke->dash(idx)); - } else skip(key); + } else skip(); } } } @@ -680,7 +681,7 @@ LottieSolidStroke* LottieParser::parseSolidStroke() else if (KEY_AS("ml")) stroke->miterLimit = getFloat(); else if (KEY_AS("fillEnabled")) stroke->hidden |= !getBool(); else if (KEY_AS("d")) parseStrokeDash(stroke); - else skip(key); + else skip(); } return stroke; } @@ -699,7 +700,7 @@ void LottieParser::getPathSet(LottiePathSet& path) } } else if (KEY_AS("x")) { path.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &path); - } else skip(key); + } else skip(); } path.type = LottieProperty::Type::PathSet; } @@ -713,7 +714,7 @@ LottiePath* LottieParser::parsePath() if (parseCommon(path, key)) continue; else if (KEY_AS("ks")) getPathSet(path->pathset); else if (parseDirection(path, key)) continue; - else skip(key); + else skip(); } return path; } @@ -736,7 +737,7 @@ LottiePolyStar* LottieParser::parsePolyStar() else if (KEY_AS("r")) parseProperty(star->rotation); else if (KEY_AS("sy")) star->type = (LottiePolyStar::Type) getInt(); else if (parseDirection(star, key)) continue; - else skip(key); + else skip(); } return star; } @@ -751,7 +752,7 @@ LottieRoundedCorner* LottieParser::parseRoundedCorner() while (auto key = nextObjectKey()) { if (parseCommon(corner, key)) continue; else if (KEY_AS("r")) parseProperty(corner->radius); - else skip(key); + else skip(); } return corner; } @@ -764,7 +765,7 @@ void LottieParser::parseColorStop(LottieGradient* gradient) if (KEY_AS("p")) gradient->colorStops.count = getInt(); else if (KEY_AS("k")) parseProperty(gradient->colorStops, gradient); else if (KEY_AS("sid")) registerSlot(gradient, getString()); - else skip(key); + else skip(); } } @@ -778,7 +779,7 @@ void LottieParser::parseGradient(LottieGradient* gradient, const char* key) else if (KEY_AS("e")) parseProperty(gradient->end, gradient); else if (KEY_AS("h")) parseProperty(gradient->height, gradient); else if (KEY_AS("a")) parseProperty(gradient->angle, gradient); - else skip(key); + else skip(); } @@ -833,7 +834,7 @@ LottieTrimpath* LottieParser::parseTrimpath() else if (KEY_AS("e")) parseProperty(trim->end); else if (KEY_AS("o")) parseProperty(trim->offset); else if (KEY_AS("m")) trim->type = static_cast(getInt()); - else skip(key); + else skip(); } return trim; } @@ -860,10 +861,10 @@ LottieRepeater* LottieParser::parseRepeater() else if (KEY_AS("s")) parseProperty(repeater->scale); else if (KEY_AS("so")) parseProperty(repeater->startOpacity); else if (KEY_AS("eo")) parseProperty(repeater->endOpacity); - else skip(key); + else skip(); } } - else skip(key); + else skip(); } return repeater; } @@ -880,7 +881,7 @@ LottieOffsetPath* LottieParser::parseOffsetPath() else if (KEY_AS("a")) parseProperty(offsetPath->offset); else if (KEY_AS("lj")) offsetPath->join = getStrokeJoin(); else if (KEY_AS("ml")) parseProperty(offsetPath->miterLimit); - else skip(key); + else skip(); } return offsetPath; } @@ -922,7 +923,7 @@ void LottieParser::parseObject(Array& parent) if (child->hidden) delete(child); else parent.push(child); } - } else skip(key); + } else skip(); } } @@ -984,7 +985,7 @@ LottieObject* LottieParser::parseAsset() else if (KEY_AS("h")) height = getFloat(); else if (KEY_AS("e")) embedded = getInt(); else if (KEY_AS("sid")) sid = getString(); - else skip(key); + else skip(); } if (data) { obj = new LottieImage; @@ -1008,7 +1009,7 @@ LottieFont* LottieParser::parseFont() else if (KEY_AS("fStyle")) font->style = getStringCopy(); else if (KEY_AS("ascent")) font->ascent = getFloat(); else if (KEY_AS("origin")) font->origin = (LottieFont::Origin) getInt(); - else skip(key); + else skip(); } return font; } @@ -1034,7 +1035,7 @@ LottieMarker* LottieParser::parseMarker() if (KEY_AS("cm")) marker->name = getStringCopy(); else if (KEY_AS("tm")) marker->time = getFloat(); else if (KEY_AS("dr")) marker->duration = getFloat(); - else skip(key); + else skip(); } return marker; @@ -1067,7 +1068,7 @@ void LottieParser::parseChars(Array& glyphs) while (auto key = nextObjectKey()) { if (KEY_AS("shapes")) parseShapes(glyph->children); } - } else skip(key); + } else skip(); } glyph->prepare(); glyphs.push(glyph); @@ -1083,7 +1084,7 @@ void LottieParser::parseFonts() while (nextArrayValue()) { comp->fonts.push(parseFont()); } - } else skip(key); + } else skip(); } } @@ -1097,7 +1098,7 @@ LottieObject* LottieParser::parseGroup() else if (KEY_AS("it")) { enterArray(); while (nextArrayValue()) parseObject(group->children); - } else skip(key); + } else skip(); } if (group->children.empty()) { delete(group); @@ -1129,7 +1130,7 @@ void LottieParser::parseShapes(Array& parent) if (child->hidden) delete(child); else parent.push(child); } - } else skip(key); + } else skip(); } } } @@ -1141,7 +1142,7 @@ void LottieParser::parseTextAlignmentOption(LottieText* text) while (auto key = nextObjectKey()) { if (KEY_AS("g")) text->alignOption.grouping = (LottieText::AlignOption::Group) getInt(); else if (KEY_AS("a")) parseProperty(text->alignOption.anchor); - else skip(key); + else skip(); } } @@ -1173,7 +1174,7 @@ void LottieParser::parseTextRange(LottieText* text) else if (KEY_AS("sm")) parseProperty(selector->smoothness); else if (KEY_AS("s")) parseProperty(selector->start); else if (KEY_AS("e")) parseProperty(selector->end); - else skip(key); + else skip(); } } else if (KEY_AS("a")) { // text style enterObject(); @@ -1189,9 +1190,9 @@ void LottieParser::parseTextRange(LottieText* text) else if (KEY_AS("p")) parseProperty(selector->style.position); else if (KEY_AS("s")) parseProperty(selector->style.scale); else if (KEY_AS("r")) parseProperty(selector->style.rotation); - else skip(key); + else skip(); } - } else skip(key); + } else skip(); } text->ranges.push(selector); @@ -1212,9 +1213,9 @@ void LottieParser::parseText(Array& parent) else if (KEY_AS("p")) { TVGLOG("LOTTIE", "Text Follow Path (p) is not supported"); - skip(key); + skip(); } - else skip(key); + else skip(); } parent.push(text); } @@ -1248,7 +1249,7 @@ LottieMask* LottieParser::parseMask() else if (valid && KEY_AS("pt")) getPathSet(mask->pathset); else if (valid && KEY_AS("o")) parseProperty(mask->opacity); else if (valid && KEY_AS("x")) parseProperty(mask->expand); - else skip(key); + else skip(); } if (!valid) { @@ -1271,7 +1272,30 @@ void LottieParser::parseMasks(LottieLayer* layer) } -void LottieParser::parseGaussianBlur(LottieGaussianBlur* effect) +void LottieParser::parseFill(LottieFxFill* effect) +{ + int idx = 0; //fill mask -> all mask -> color -> invert -> h feather -> v feather -> opacity + enterArray(); + while (nextArrayValue()) { + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("v")) { + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("k")) { + if (idx == 2) parsePropertyInternal(effect->color); + else if (idx == 6) parsePropertyInternal(effect->opacity); + else skip(); + } else skip(); + } + ++idx; + } else skip(); + } + } +} + + +void LottieParser::parseGaussianBlur(LottieFxGaussianBlur* effect) { int idx = 0; //blurness -> direction -> wrap enterArray(); @@ -1285,17 +1309,17 @@ void LottieParser::parseGaussianBlur(LottieGaussianBlur* effect) if (idx == 0) parsePropertyInternal(effect->blurness); else if (idx == 1) parsePropertyInternal(effect->direction); else if (idx == 2) parsePropertyInternal(effect->wrap); - else skip(key); + else skip(); ++idx; - } else skip(key); + } else skip(); } - } else skip(key); + } else skip(); } } } -void LottieParser::parseDropShadow(LottieDropShadow* effect) +void LottieParser::parseDropShadow(LottieFxDropShadow* effect) { int idx = 0; //color -> opacity -> angle -> distance -> blur enterArray(); @@ -1311,11 +1335,11 @@ void LottieParser::parseDropShadow(LottieDropShadow* effect) else if (idx == 2) parsePropertyInternal(effect->angle); else if (idx == 3) parsePropertyInternal(effect->distance); else if (idx == 4) parsePropertyInternal(effect->blurness); - else skip(key); + else skip(); ++idx; - } else skip(key); + } else skip(); } - } else skip(key); + } else skip(); } } } @@ -1324,12 +1348,16 @@ void LottieParser::parseDropShadow(LottieDropShadow* effect) void LottieParser::parseEffect(LottieEffect* effect) { switch (effect->type) { + case LottieEffect::Fill: { + parseFill(static_cast(effect)); + break; + } case LottieEffect::GaussianBlur: { - parseGaussianBlur(static_cast(effect)); + parseGaussianBlur(static_cast(effect)); break; } case LottieEffect::DropShadow: { - parseDropShadow(static_cast(effect)); + parseDropShadow(static_cast(effect)); break; } default: break; @@ -1339,11 +1367,10 @@ void LottieParser::parseEffect(LottieEffect* effect) void LottieParser::parseEffects(LottieLayer* layer) { - auto invalid = true; - enterArray(); while (nextArrayValue()) { LottieEffect* effect = nullptr; + auto invalid = true; enterObject(); while (auto key = nextObjectKey()) { //type must be priortized. @@ -1355,12 +1382,12 @@ void LottieParser::parseEffects(LottieLayer* layer) } else if (effect && KEY_AS("en")) effect->enable = getInt(); else if (effect && KEY_AS("ef")) parseEffect(effect); - else skip(key); + else skip(); } //TODO: remove when all effects were guaranteed. if (invalid) { TVGLOG("LOTTIE", "Not supported Layer Effect = %d", effect ? (int)effect->type : -1); - while (auto key = nextObjectKey()) skip(key); + while (nextObjectKey()) skip(); } else layer->effects.push(effect); } } @@ -1412,7 +1439,7 @@ LottieLayer* LottieParser::parseLayer(LottieLayer* precomp) else if (KEY_AS("td")) layer->matteSrc = getInt(); //used for matte layer else if (KEY_AS("t")) parseText(layer->children); else if (KEY_AS("ef")) parseEffects(layer); - else skip(key); + else skip(); } layer->prepare(&color); @@ -1496,7 +1523,7 @@ bool LottieParser::apply(LottieSlot* slot, bool byDefault) context.parent = obj; while (auto key = nextObjectKey()) { if (KEY_AS("p")) parseColorStop(static_cast(obj)); - else skip(key); + else skip(); } break; } @@ -1509,7 +1536,7 @@ bool LottieParser::apply(LottieSlot* slot, bool byDefault) case LottieProperty::Type::Image: { while (auto key = nextObjectKey()) { if (KEY_AS("p")) obj = parseAsset(); - else skip(key); + else skip(); } context.parent = obj; break; @@ -1556,7 +1583,7 @@ void LottieParser::captureSlots(const char* key) if (invalid) { TVGERR("LOTTIE", "Invalid Slots!"); - skip(key); + skip(); return; } @@ -1567,7 +1594,7 @@ void LottieParser::captureSlots(const char* key) memcpy(slots + 1, begin, len); slots[len] = '\0'; - skip(key); + skip(); } @@ -1600,7 +1627,7 @@ bool LottieParser::parse() else if (KEY_AS("chars")) parseChars(glyphs); else if (KEY_AS("markers")) parseMarkers(); else if (KEY_AS("slots")) captureSlots(key); - else skip(key); + else skip(); } if (Invalid() || !comp->root) { diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParser.h b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParser.h index d8474396a..c4f2948ad 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParser.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParser.h @@ -100,8 +100,9 @@ struct LottieParser : LookaheadParserHandler LottieFont* parseFont(); LottieMarker* parseMarker(); - void parseGaussianBlur(LottieGaussianBlur* effect); - void parseDropShadow(LottieDropShadow* effect); + void parseFill(LottieFxFill* effect); + void parseGaussianBlur(LottieFxGaussianBlur* effect); + void parseDropShadow(LottieFxDropShadow* effect); bool parseDirection(LottieShape* shape, const char* key); bool parseCommon(LottieObject* obj, const char* key); diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParserHandler.cpp b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParserHandler.cpp index 51673fd82..bd23516a0 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParserHandler.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParserHandler.cpp @@ -219,7 +219,7 @@ const char* LookaheadParserHandler::nextObjectKey() } -void LookaheadParserHandler::skip(const char* key) +void LookaheadParserHandler::skip() { if (peekType() == kArrayType) { enterArray(); diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParserHandler.h b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParserHandler.h index 150912e93..25cc13cdf 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParserHandler.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieParserHandler.h @@ -192,7 +192,7 @@ struct LookaheadParserHandler void getNull(); bool parseNext(); const char* nextObjectKey(); - void skip(const char* key); + void skip(); void skipOut(int depth); int peekType(); char* getPos(); diff --git a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieProperty.h b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieProperty.h index 932b5e79e..4b3517b51 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieProperty.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/loaders/lottie/tvgLottieProperty.h @@ -25,7 +25,7 @@ #include #include "tvgMath.h" -#include "tvgLottieCommon.h" +#include "tvgLottieData.h" #include "tvgLottieInterpolator.h" #include "tvgLottieExpressions.h" #include "tvgLottieModifier.h" @@ -222,6 +222,8 @@ float _frameNo(T* frames, int32_t key) template float _loop(T* frames, float frameNo, LottieExpression* exp) { + if (exp->loop.mode == LottieExpression::LoopMode::None) return frameNo; + if (frameNo >= exp->loop.in || frameNo < frames->first().no || frameNo < frames->last().no) return frameNo; frameNo -= frames->first().no; @@ -329,7 +331,7 @@ struct LottieGenericProperty : LottieProperty { if (exps && exp) { T out{}; - if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp); + frameNo = _loop(frames, frameNo, exp); if (exps->result>(frameNo, out, exp)) return out; } return operator()(frameNo); @@ -496,7 +498,7 @@ struct LottiePathSet : LottieProperty bool operator()(float frameNo, Array& cmds, Array& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offsetPath, LottieExpressions* exps) { if (exps && exp) { - if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp); + frameNo = _loop(frames, frameNo, exp); if (exps->result(frameNo, cmds, pts, transform, roundness, offsetPath, exp)) return true; } return operator()(frameNo, cmds, pts, transform, roundness, offsetPath); @@ -585,7 +587,7 @@ struct LottieColorStop : LottieProperty Result operator()(float frameNo, Fill* fill, LottieExpressions* exps) { if (exps && exp) { - if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp); + frameNo = _loop(frames, frameNo, exp); if (exps->result(frameNo, fill, exp)) return Result::Success; } @@ -719,7 +721,7 @@ struct LottiePosition : LottieProperty { Point out{}; if (exps && exp) { - if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp); + frameNo = _loop(frames, frameNo, exp); if (exps->result(frameNo, out, exp)) return out; } return operator()(frameNo); diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwCommon.h b/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwCommon.h index 4ced7d5ed..ad70be845 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwCommon.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwCommon.h @@ -574,7 +574,9 @@ bool rasterConvertCS(RenderSurface* surface, ColorSpace to); bool effectGaussianBlur(SwCompositor* cmp, SwSurface* surface, const RenderEffectGaussianBlur* params); bool effectGaussianBlurPrepare(RenderEffectGaussianBlur* effect); -bool effectDropShadow(SwCompositor* cmp, SwSurface* surfaces[2], const RenderEffectDropShadow* params, uint8_t opacity, bool direct); +bool effectDropShadow(SwCompositor* cmp, SwSurface* surfaces[2], const RenderEffectDropShadow* params, bool direct); bool effectDropShadowPrepare(RenderEffectDropShadow* effect); +bool effectFillPrepare(RenderEffectFill* effect); +bool effectFill(SwCompositor* cmp, const RenderEffectFill* params, bool direct); #endif /* _TVG_SW_COMMON_H_ */ diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwPostEffect.cpp b/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwPostEffect.cpp index 4168917b7..ad106a916 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwPostEffect.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwPostEffect.cpp @@ -150,7 +150,6 @@ bool effectGaussianBlurPrepare(RenderEffectGaussianBlur* params) //invalid if (extends == 0) { - params->invalid = true; free(rd); return false; } @@ -158,6 +157,7 @@ bool effectGaussianBlurPrepare(RenderEffectGaussianBlur* params) _gaussianExtendRegion(params->extend, extends, params->direction); params->rd = rd; + params->valid = true; return true; } @@ -165,11 +165,6 @@ bool effectGaussianBlurPrepare(RenderEffectGaussianBlur* params) bool effectGaussianBlur(SwCompositor* cmp, SwSurface* surface, const RenderEffectGaussianBlur* params) { - if (cmp->image.channelSize != sizeof(uint32_t)) { - TVGERR("SW_ENGINE", "Not supported grayscale Gaussian Blur!"); - return false; - } - auto& buffer = surface->compositor->image; auto data = static_cast(params->rd); auto& bbox = cmp->bbox; @@ -310,7 +305,6 @@ bool effectDropShadowPrepare(RenderEffectDropShadow* params) //invalid if (extends == 0 || params->color[3] == 0) { - params->invalid = true; free(rd); return false; } @@ -327,6 +321,7 @@ bool effectDropShadowPrepare(RenderEffectDropShadow* params) _dropShadowExtendRegion(params->extend, extends, rd->offset); params->rd = rd; + params->valid = true; return true; } @@ -335,13 +330,8 @@ bool effectDropShadowPrepare(RenderEffectDropShadow* params) //A quite same integration with effectGaussianBlur(). See it for detailed comments. //surface[0]: the original image, to overlay it into the filtered image. //surface[1]: temporary buffer for generating the filtered image. -bool effectDropShadow(SwCompositor* cmp, SwSurface* surface[2], const RenderEffectDropShadow* params, uint8_t opacity, bool direct) +bool effectDropShadow(SwCompositor* cmp, SwSurface* surface[2], const RenderEffectDropShadow* params, bool direct) { - if (cmp->image.channelSize != sizeof(uint32_t)) { - TVGERR("SW_ENGINE", "Not supported grayscale Drop Shadow!"); - return false; - } - //FIXME: if the body is partially visible due to clipping, the shadow also becomes partially visible. auto data = static_cast(params->rd); @@ -357,7 +347,8 @@ bool effectDropShadow(SwCompositor* cmp, SwSurface* surface[2], const RenderEffe auto stride = cmp->image.stride; auto front = cmp->image.buf32; auto back = buffer[1]->buf32; - opacity = MULTIPLY(params->color[3], opacity); + + auto opacity = direct ? MULTIPLY(params->color[3], cmp->opacity) : params->color[3]; TVGLOG("SW_ENGINE", "DropShadow region(%ld, %ld, %ld, %ld) params(%f %f %f), level(%d)", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y, params->angle, params->distance, params->sigma, data->level); @@ -406,5 +397,56 @@ bool effectDropShadow(SwCompositor* cmp, SwSurface* surface[2], const RenderEffe d += cmp->image.stride; } + return true; +} + + +/************************************************************************/ +/* Fill Implementation */ +/************************************************************************/ + +bool effectFillPrepare(RenderEffectFill* params) +{ + params->valid = true; + return true; +} + + +bool effectFill(SwCompositor* cmp, const RenderEffectFill* params, bool direct) +{ + auto opacity = direct ? MULTIPLY(params->color[3], cmp->opacity) : params->color[3]; + + auto& bbox = cmp->bbox; + auto w = size_t(bbox.max.x - bbox.min.x); + auto h = size_t(bbox.max.y - bbox.min.y); + auto color = cmp->recoverSfc->join(params->color[0], params->color[1], params->color[2], 255); + + TVGLOG("SW_ENGINE", "Fill region(%ld, %ld, %ld, %ld), param(%d %d %d %d)", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y, params->color[0], params->color[1], params->color[2], params->color[3]); + + if (direct) { + auto dbuffer = cmp->recoverSfc->buf32 + (bbox.min.y * cmp->recoverSfc->stride + bbox.min.x); + auto sbuffer = cmp->image.buf32 + (bbox.min.y * cmp->image.stride + bbox.min.x); + for (size_t y = 0; y < h; ++y) { + auto dst = dbuffer; + auto src = sbuffer; + for (size_t x = 0; x < w; ++x, ++dst, ++src) { + auto a = MULTIPLY(opacity, A(*src)); + auto tmp = ALPHA_BLEND(color, a); + *dst = tmp + ALPHA_BLEND(*dst, 255 - a); + } + dbuffer += cmp->image.stride; + sbuffer += cmp->recoverSfc->stride; + } + cmp->valid = true; //no need the subsequent composition + } else { + auto dbuffer = cmp->image.buf32 + (bbox.min.y * cmp->image.stride + bbox.min.x); + for (size_t y = 0; y < h; ++y) { + auto dst = dbuffer; + for (size_t x = 0; x < w; ++x, ++dst) { + *dst = ALPHA_BLEND(color, MULTIPLY(opacity, A(*dst))); + } + dbuffer += cmp->image.stride; + } + } return true; } \ No newline at end of file diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp b/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp index 707978ea2..ea5822463 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp @@ -634,12 +634,15 @@ bool SwRenderer::endComposite(RenderCompositor* cmp) if (!cmp) return false; auto p = static_cast(cmp); - p->valid = true; //Recover Context surface = p->recoverSfc; surface->compositor = p->recoverCmp; + //only invalid (currently used) surface can be composited + if (p->valid) return true; + p->valid = true; + //Default is alpha blending if (p->method == MaskMethod::None) { Matrix m = {1, 0, 0, 0, 1, 0, 0, 0, 1}; @@ -655,17 +658,23 @@ bool SwRenderer::prepare(RenderEffect* effect) switch (effect->type) { case SceneEffect::GaussianBlur: return effectGaussianBlurPrepare(static_cast(effect)); case SceneEffect::DropShadow: return effectDropShadowPrepare(static_cast(effect)); + case SceneEffect::Fill: return effectFillPrepare(static_cast(effect)); default: return false; } } -bool SwRenderer::effect(RenderCompositor* cmp, const RenderEffect* effect, uint8_t opacity, bool direct) +bool SwRenderer::effect(RenderCompositor* cmp, const RenderEffect* effect, bool direct) { - if (effect->invalid) return false; + if (!effect->valid) return false; auto p = static_cast(cmp); + if (p->image.channelSize != sizeof(uint32_t)) { + TVGERR("SW_ENGINE", "Not supported grayscale Gaussian Blur!"); + return false; + } + switch (effect->type) { case SceneEffect::GaussianBlur: { return effectGaussianBlur(p, request(surface->channelSize, true), static_cast(effect)); @@ -675,10 +684,13 @@ bool SwRenderer::effect(RenderCompositor* cmp, const RenderEffect* effect, uint8 cmp1->compositor->valid = false; auto cmp2 = request(surface->channelSize, true); SwSurface* surfaces[] = {cmp1, cmp2}; - auto ret = effectDropShadow(p, surfaces, static_cast(effect), opacity, direct); + auto ret = effectDropShadow(p, surfaces, static_cast(effect), direct); cmp1->compositor->valid = true; return ret; } + case SceneEffect::Fill: { + return effectFill(p, static_cast(effect), direct); + } default: return false; } } diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwRenderer.h b/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwRenderer.h index ca96da880..a15fdb570 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwRenderer.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/sw_engine/tvgSwRenderer.h @@ -61,7 +61,7 @@ class SwRenderer : public RenderMethod void clearCompositors(); bool prepare(RenderEffect* effect) override; - bool effect(RenderCompositor* cmp, const RenderEffect* effect, uint8_t opacity, bool direct) override; + bool effect(RenderCompositor* cmp, const RenderEffect* effect, bool direct) override; static SwRenderer* gen(); static bool init(uint32_t threads); diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgCanvas.cpp b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgCanvas.cpp index 27ae181d2..eb0d38ac7 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgCanvas.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgCanvas.cpp @@ -49,16 +49,10 @@ Result Canvas::push(Paint* target, Paint* at) noexcept } -Result Canvas::clear(bool paints, bool buffer) noexcept -{ - return pImpl->clear(paints, buffer); -} - - -Result Canvas::draw() noexcept +Result Canvas::draw(bool clear) noexcept { TVGLOG("RENDERER", "Draw S. -------------------------------- Canvas(%p)", this); - auto ret = pImpl->draw(); + auto ret = pImpl->draw(clear); TVGLOG("RENDERER", "Draw E. -------------------------------- Canvas(%p)", this); return ret; @@ -68,7 +62,6 @@ Result Canvas::draw() noexcept Result Canvas::update(Paint* paint) noexcept { TVGLOG("RENDERER", "Update S. ------------------------------ Canvas(%p)", this); - if (pImpl->scene->paints().empty() || pImpl->status == Status::Drawing) return Result::InsufficientCondition; auto ret = pImpl->update(paint, false); TVGLOG("RENDERER", "Update E. ------------------------------ Canvas(%p)", this); diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgCanvas.h b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgCanvas.h index c521cf26d..f609df4c9 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgCanvas.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgCanvas.h @@ -63,29 +63,12 @@ struct Canvas::Impl return update(target, true); } - Result clear(bool paints, bool buffer) - { - auto ret = Result::Success; - - if (status == Status::Drawing) return Result::InsufficientCondition; - - //Clear render target - if (buffer && !renderer->clear()) { - ret = Result::InsufficientCondition; - } - - if (paints) scene->remove(); - - return ret; - } - Result remove(Paint* paint) { if (status == Status::Drawing) return Result::InsufficientCondition; return scene->remove(paint); } - Result update(Paint* paint, bool force) { Array clips; @@ -101,9 +84,13 @@ struct Canvas::Impl return Result::Success; } - Result draw() + Result draw(bool clear) { - if (status == Status::Drawing || scene->paints().empty()) return Result::InsufficientCondition; + if (status == Status::Drawing) return Result::InsufficientCondition; + + if (clear && !renderer->clear()) return Result::InsufficientCondition; + + if (scene->paints().empty()) return Result::InsufficientCondition; if (status == Status::Damaged) update(nullptr, false); @@ -112,6 +99,7 @@ struct Canvas::Impl if (!PP(scene)->render(renderer) || !renderer->postRender()) return Result::InsufficientCondition; status = Status::Drawing; + return Result::Success; } diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgLoader.cpp b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgLoader.cpp index c809444e3..0c567e78d 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgLoader.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgLoader.cpp @@ -429,7 +429,7 @@ LoadModule* LoaderMgr::loader(const char* name, const char* data, uint32_t size, //function is dedicated for ttf loader (the only supported font loader) auto loader = new TtfLoader; - if (loader->open(data, size, "", copy, std::move(colorReplacement))) { + if (loader->open(data, size, "", copy, colorReplacement)) { loader->hashpath = strdup(name); loader->pathcache = true; ScopedLock lock(key); diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgRender.h b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgRender.h index ba735bcb3..b8b454b48 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgRender.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgRender.h @@ -260,7 +260,7 @@ struct RenderEffect RenderData rd = nullptr; RenderRegion extend = {0, 0, 0, 0}; SceneEffect type; - bool invalid = false; + bool valid = false; virtual ~RenderEffect() { @@ -311,6 +311,22 @@ struct RenderEffectDropShadow : RenderEffect } }; +struct RenderEffectFill : RenderEffect +{ + uint8_t color[4]; //rgba + + static RenderEffectFill* gen(va_list& args) + { + auto inst = new RenderEffectFill; + inst->color[0] = va_arg(args, int); + inst->color[1] = va_arg(args, int); + inst->color[2] = va_arg(args, int); + inst->color[3] = std::min(va_arg(args, int), 255); + inst->type = SceneEffect::Fill; + return inst; + } +}; + class RenderMethod { private: @@ -344,7 +360,7 @@ class RenderMethod virtual bool endComposite(RenderCompositor* cmp) = 0; virtual bool prepare(RenderEffect* effect) = 0; - virtual bool effect(RenderCompositor* cmp, const RenderEffect* effect, uint8_t opacity, bool direct) = 0; + virtual bool effect(RenderCompositor* cmp, const RenderEffect* effect, bool direct) = 0; }; static inline bool MASK_REGION_MERGING(MaskMethod method) diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgScene.cpp b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgScene.cpp index b846c75e9..4072cbaa0 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgScene.cpp +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgScene.cpp @@ -109,6 +109,10 @@ Result Scene::push(SceneEffect effect, ...) noexcept re = RenderEffectDropShadow::gen(args); break; } + case SceneEffect::Fill: { + re = RenderEffectFill::gen(args); + break; + } default: break; } diff --git a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgScene.h b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgScene.h index c320978d0..279801e29 100644 --- a/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgScene.h +++ b/libfenrir/src/main/jni/animation/thorvg/src/renderer/tvgScene.h @@ -141,9 +141,10 @@ struct Scene::Impl if (cmp) { //Apply post effects if any. if (effects) { - auto direct = effects->count == 1 ? true : false; + //Notify the possiblity of the direct composition of the effect result to the origin surface. + auto direct = (effects->count == 1) & (compFlag == CompositionFlag::PostProcessing); for (auto e = effects->begin(); e < effects->end(); ++e) { - renderer->effect(cmp, *e, opacity, direct); + renderer->effect(cmp, *e, direct); } } renderer->endComposite(cmp); @@ -176,7 +177,7 @@ struct Scene::Impl if (effects) { for (auto e = effects->begin(); e < effects->end(); ++e) { auto effect = *e; - if (effect->rd || renderer->prepare(effect)) { + if (effect->valid || renderer->prepare(effect)) { ex = std::min(ex, effect->extend.x); ey = std::min(ey, effect->extend.y); ew = std::max(ew, effect->extend.w); diff --git a/libfenrir/src/main/jni/animation/thorvg/thorvg-1.0-pre7.tar.gz b/libfenrir/src/main/jni/animation/thorvg/thorvg-1.0-pre7.tar.gz deleted file mode 100644 index fbc156b85..000000000 Binary files a/libfenrir/src/main/jni/animation/thorvg/thorvg-1.0-pre7.tar.gz and /dev/null differ diff --git a/libfenrir/src/main/jni/animation/thorvg/thorvg-1.0-pre8.tar.gz b/libfenrir/src/main/jni/animation/thorvg/thorvg-1.0-pre8.tar.gz new file mode 100644 index 000000000..7bd51141c Binary files /dev/null and b/libfenrir/src/main/jni/animation/thorvg/thorvg-1.0-pre8.tar.gz differ diff --git a/libfenrir/src/main/jni/animation/thorvg_jni.cpp b/libfenrir/src/main/jni/animation/thorvg_jni.cpp index 60da3cb34..5f4e4d19c 100644 --- a/libfenrir/src/main/jni/animation/thorvg_jni.cpp +++ b/libfenrir/src/main/jni/animation/thorvg_jni.cpp @@ -129,7 +129,7 @@ Java_dev_ragnarok_fenrir_module_animation_thorvg_ThorVGSVGRender_createBitmapNat return; } - canvas->push(std::move(picture)); + canvas->push(picture); if (canvas->draw() == tvg::Result::Success) { canvas->sync(); } @@ -347,7 +347,6 @@ Java_dev_ragnarok_fenrir_module_animation_thorvg_ThorVGLottieDrawable_nSetBuffer info->canvas->target((uint32_t *) pixels, (uint32_t) width, (uint32_t) width, (uint32_t) height, tvg::ColorSpace::ABGR8888); - info->canvas->clear(false); float scale; float shiftX = 0.0f, shiftY = 0.0f; @@ -395,7 +394,6 @@ Java_dev_ragnarok_fenrir_module_animation_thorvg_ThorVGLottieDrawable_nGetFrame( void *pixels; if (AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0) { - info->canvas->clear(false); info->animation->frame((float) frame); if (!info->isCanvasPushed) { info->isCanvasPushed = true; @@ -403,7 +401,7 @@ Java_dev_ragnarok_fenrir_module_animation_thorvg_ThorVGLottieDrawable_nGetFrame( } else { info->canvas->update(info->animation->picture()); } - if (info->canvas->draw() == tvg::Result::Success) { + if (info->canvas->draw(true) == tvg::Result::Success) { info->canvas->sync(); } AndroidBitmap_unlockPixels(env, bitmap); @@ -474,7 +472,7 @@ Java_dev_ragnarok_fenrir_module_animation_thorvg_ThorVGLottie2Gif_lottie2gif(JNI auto bg = tvg::Shape::gen(); bg->appendRect(0, 0, (float) w, (float) h); bg->fill(((bgColor >> 16) & 0xff), ((bgColor >> 8) & 0xff), (bgColor & 0xff)); - info.canvas->push(std::move(bg)); + info.canvas->push(bg); } info.canvas->push(info.animation->picture()); @@ -534,11 +532,10 @@ Java_dev_ragnarok_fenrir_module_animation_thorvg_ThorVGLottie2Gif_lottie2gif(JNI env->CallVoidMethod(store_Wlistener, mth_start); for (auto p = 0.0f; p < duration; p += delay) { - info.canvas->clear(false); auto frameNo = info.animation->totalFrame() * (p / duration); info.animation->frame(frameNo); info.canvas->update(); - if (info.canvas->draw() == tvg::Result::Success) { + if (info.canvas->draw(true) == tvg::Result::Success) { info.canvas->sync(); } if (!gifWriteFrame(&writer, reinterpret_cast(pixels), w, h, @@ -553,11 +550,10 @@ Java_dev_ragnarok_fenrir_module_animation_thorvg_ThorVGLottie2Gif_lottie2gif(JNI env->CallVoidMethod(store_Wlistener, mth_end); } else { for (auto p = 0.0f; p < duration; p += delay) { - info.canvas->clear(false); auto frameNo = info.animation->totalFrame() * (p / duration); info.animation->frame(frameNo); info.canvas->update(info.animation->picture()); - if (info.canvas->draw() == tvg::Result::Success) { + if (info.canvas->draw(true) == tvg::Result::Success) { info.canvas->sync(); } diff --git a/material/java/com/google/android/material/appbar/res/animator/m3_appbar_state_list_animator.xml b/material/java/com/google/android/material/appbar/res/animator/m3_appbar_state_list_animator.xml index b1805e1e4..fb7562206 100644 --- a/material/java/com/google/android/material/appbar/res/animator/m3_appbar_state_list_animator.xml +++ b/material/java/com/google/android/material/appbar/res/animator/m3_appbar_state_list_animator.xml @@ -23,7 +23,7 @@ @@ -31,7 +31,7 @@ @@ -39,7 +39,7 @@ diff --git a/material/java/com/google/android/material/appbar/res/values/dimens.xml b/material/java/com/google/android/material/appbar/res/values/dimens.xml index e08d84692..765fc32b6 100644 --- a/material/java/com/google/android/material/appbar/res/values/dimens.xml +++ b/material/java/com/google/android/material/appbar/res/values/dimens.xml @@ -20,10 +20,10 @@ 56dp - @dimen/m3_comp_top_app_bar_small_container_height - @dimen/m3_comp_top_app_bar_medium_container_height + @dimen/m3_comp_app_bar_small_container_height + @dimen/m3_comp_app_bar_medium_container_height 136dp - @dimen/m3_comp_top_app_bar_large_container_height + @dimen/m3_comp_app_bar_large_container_height 152dp 16dp diff --git a/material/java/com/google/android/material/appbar/res/values/styles.xml b/material/java/com/google/android/material/appbar/res/values/styles.xml index 2755efdb3..f5741c3f2 100644 --- a/material/java/com/google/android/material/appbar/res/values/styles.xml +++ b/material/java/com/google/android/material/appbar/res/values/styles.xml @@ -147,8 +147,8 @@ @@ -225,12 +221,12 @@ colors for text and iconography). Use with MaterialToolbar to get navigation icon and menu icon coloring. --> - + - - - ?attr/colorSurface - ?attr/colorSurfaceContainer - 64dp - @dimen/m3_sys_elevation_level0 - - ?attr/colorOnSurface - - ?attr/colorOnSurfaceVariant - - ?attr/textAppearanceTitleLarge - ?attr/colorOnSurface - - @dimen/m3_sys_elevation_level2 + + + ?attr/colorSurface + ?attr/colorSurfaceContainer + @dimen/m3_sys_elevation_level0 + @dimen/m3_sys_elevation_level2 + ?attr/colorOnSurface + ?attr/colorOnSurface + ?attr/colorOnSurfaceVariant - - - 112dp - - ?attr/textAppearanceHeadlineSmall - ?attr/colorOnSurface + + 64dp + ?attr/textAppearanceTitleLarge + ?attr/textAppearanceLabelMedium - - - 152dp - - ?attr/textAppearanceHeadlineMedium - ?attr/colorOnSurface + + 112dp + ?attr/textAppearanceHeadlineSmall + + + 152dp + ?attr/textAppearanceHeadlineMedium diff --git a/material/java/com/google/android/material/badge/res/values/tokens.xml b/material/java/com/google/android/material/badge/res/values/tokens.xml index 722cced06..4e06cdda9 100644 --- a/material/java/com/google/android/material/badge/res/values/tokens.xml +++ b/material/java/com/google/android/material/badge/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/bottomappbar/res/values/tokens.xml b/material/java/com/google/android/material/bottomappbar/res/values/tokens.xml index 72bd5d5e2..d7714edf6 100644 --- a/material/java/com/google/android/material/bottomappbar/res/values/tokens.xml +++ b/material/java/com/google/android/material/bottomappbar/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/bottomnavigation/BottomNavigationView.java b/material/java/com/google/android/material/bottomnavigation/BottomNavigationView.java index 090a7f616..1af37e0d6 100644 --- a/material/java/com/google/android/material/bottomnavigation/BottomNavigationView.java +++ b/material/java/com/google/android/material/bottomnavigation/BottomNavigationView.java @@ -20,9 +20,11 @@ import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; +import android.annotation.SuppressLint; import android.content.Context; import androidx.appcompat.widget.TintTypedArray; import android.util.AttributeSet; +import android.view.MotionEvent; import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -127,6 +129,14 @@ public BottomNavigationView( applyWindowInsets(); } + @SuppressLint("ClickableViewAccessibility") + @Override + public boolean onTouchEvent(@NonNull MotionEvent event) { + super.onTouchEvent(event); + // Consume all events to avoid views under the BottomNavigationView from receiving touch events. + return true; + } + private void applyWindowInsets() { ViewUtils.doOnApplyWindowInsets( this, diff --git a/material/java/com/google/android/material/bottomnavigation/res/values/tokens.xml b/material/java/com/google/android/material/bottomnavigation/res/values/tokens.xml index 02d8af864..45b461b1b 100644 --- a/material/java/com/google/android/material/bottomnavigation/res/values/tokens.xml +++ b/material/java/com/google/android/material/bottomnavigation/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/bottomsheet/res/values/tokens.xml b/material/java/com/google/android/material/bottomsheet/res/values/tokens.xml index 561340da9..bf5f094d7 100644 --- a/material/java/com/google/android/material/bottomsheet/res/values/tokens.xml +++ b/material/java/com/google/android/material/bottomsheet/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/button/MaterialButton.java b/material/java/com/google/android/material/button/MaterialButton.java index 4559076a4..3a2740d09 100644 --- a/material/java/com/google/android/material/button/MaterialButton.java +++ b/material/java/com/google/android/material/button/MaterialButton.java @@ -29,6 +29,7 @@ import static java.lang.Math.max; import static java.lang.Math.min; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; @@ -322,6 +323,7 @@ private SpringForce createSpringForce() { } @NonNull + @SuppressLint("KotlinPropertyAccess") String getA11yClassName() { if (!TextUtils.isEmpty(accessibilityClassName)) { return accessibilityClassName; @@ -330,7 +332,8 @@ String getA11yClassName() { return (isCheckable() ? CompoundButton.class : Button.class).getName(); } - void setA11yClassName(@Nullable String className) { + @RestrictTo(LIBRARY_GROUP) + public void setA11yClassName(@Nullable String className) { accessibilityClassName = className; } diff --git a/material/java/com/google/android/material/button/MaterialSplitButton.java b/material/java/com/google/android/material/button/MaterialSplitButton.java index 1ad8df7b9..6839355e1 100644 --- a/material/java/com/google/android/material/button/MaterialSplitButton.java +++ b/material/java/com/google/android/material/button/MaterialSplitButton.java @@ -21,9 +21,12 @@ import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap; import android.content.Context; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -104,6 +107,25 @@ public void addView(@NonNull View child, int index, @Nullable ViewGroup.LayoutPa super.addView(child, index, params); if (indexOfChild(child) == 1) { buttonChild.setCheckable(true); + buttonChild.setA11yClassName(Button.class.getName()); + if (VERSION.SDK_INT >= VERSION_CODES.R) { + // Set initial content description based on checked state when focused. + buttonChild.setStateDescription( + getResources() + .getString( + buttonChild.isChecked() + ? R.string.mtrl_button_expanded_content_description + : R.string.mtrl_button_collapsed_content_description)); + + buttonChild.addOnCheckedChangeListener( + (button, isChecked) -> + button.setStateDescription( + getResources() + .getString( + isChecked + ? R.string.mtrl_button_expanded_content_description + : R.string.mtrl_button_collapsed_content_description))); + } } } } diff --git a/material/java/com/google/android/material/button/res/values/button_group_tokens.xml b/material/java/com/google/android/material/button/res/values/button_group_tokens.xml index fe6b2d38b..683e28a4b 100644 --- a/material/java/com/google/android/material/button/res/values/button_group_tokens.xml +++ b/material/java/com/google/android/material/button/res/values/button_group_tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/button/res/values/icon_btn_tokens.xml b/material/java/com/google/android/material/button/res/values/icon_btn_tokens.xml index 84a488f45..613720de2 100644 --- a/material/java/com/google/android/material/button/res/values/icon_btn_tokens.xml +++ b/material/java/com/google/android/material/button/res/values/icon_btn_tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/button/res/values/split_button_tokens.xml b/material/java/com/google/android/material/button/res/values/split_button_tokens.xml index 9a766af73..f89b6ceb9 100644 --- a/material/java/com/google/android/material/button/res/values/split_button_tokens.xml +++ b/material/java/com/google/android/material/button/res/values/split_button_tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/button/res/values/strings.xml b/material/java/com/google/android/material/button/res/values/strings.xml new file mode 100644 index 000000000..64f93a1c0 --- /dev/null +++ b/material/java/com/google/android/material/button/res/values/strings.xml @@ -0,0 +1,21 @@ + + + + + Expanded + Collapsed + diff --git a/material/java/com/google/android/material/button/res/values/tokens.xml b/material/java/com/google/android/material/button/res/values/tokens.xml index a7e105381..9900cddff 100644 --- a/material/java/com/google/android/material/button/res/values/tokens.xml +++ b/material/java/com/google/android/material/button/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/card/res/values/tokens.xml b/material/java/com/google/android/material/card/res/values/tokens.xml index 3baa6b101..24f00149d 100644 --- a/material/java/com/google/android/material/card/res/values/tokens.xml +++ b/material/java/com/google/android/material/card/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/checkbox/res/values/tokens.xml b/material/java/com/google/android/material/checkbox/res/values/tokens.xml index 06b633c3a..65338e094 100644 --- a/material/java/com/google/android/material/checkbox/res/values/tokens.xml +++ b/material/java/com/google/android/material/checkbox/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/chip/res/values/tokens.xml b/material/java/com/google/android/material/chip/res/values/tokens.xml index f397d625a..522d09da2 100644 --- a/material/java/com/google/android/material/chip/res/values/tokens.xml +++ b/material/java/com/google/android/material/chip/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral12.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral12.xml index bf5d12258..baedc9fbf 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral12.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral12.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral17.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral17.xml index da70cf79b..040bbe456 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral17.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral17.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral22.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral22.xml index 916cab8d5..12e958623 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral22.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral22.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral24.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral24.xml index 579bc5dc5..a1df00d6c 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral24.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral24.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral4.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral4.xml index 9796e28d9..70ee99b51 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral4.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral4.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral6.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral6.xml index 1a65025b7..2e84cc4ca 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral6.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral6.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral87.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral87.xml index 8ffe132f5..5276abb21 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral87.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral87.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral92.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral92.xml index 308b8a311..08c8eaa67 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral92.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral92.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral94.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral94.xml index c5b6f4af9..c4b351500 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral94.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral94.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral96.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral96.xml index bd3ca2ab5..5d27f83d0 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral96.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral96.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral98.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral98.xml index 440397550..4c161bed1 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral98.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral98.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral_variant98.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral_variant98.xml index c17490ec5..a49eb0a62 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral_variant98.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_neutral_variant98.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_primary98.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_primary98.xml index 062496d17..2cf02a6f6 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_primary98.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_primary98.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_secondary98.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_secondary98.xml index 8a7b4677b..26de35bf3 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_secondary98.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_secondary98.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_tertiary98.xml b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_tertiary98.xml index 318dc0050..4e588c60b 100644 --- a/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_tertiary98.xml +++ b/material/java/com/google/android/material/color/res/color-v31/m3_ref_palette_dynamic_tertiary98.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/values-v31/tokens.xml b/material/java/com/google/android/material/color/res/values-v31/tokens.xml index 2849e5df1..f00225abd 100644 --- a/material/java/com/google/android/material/color/res/values-v31/tokens.xml +++ b/material/java/com/google/android/material/color/res/values-v31/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/values-v34/tokens.xml b/material/java/com/google/android/material/color/res/values-v34/tokens.xml index f2fb8b197..f7ab9e2db 100644 --- a/material/java/com/google/android/material/color/res/values-v34/tokens.xml +++ b/material/java/com/google/android/material/color/res/values-v34/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/values-v35/tokens.xml b/material/java/com/google/android/material/color/res/values-v35/tokens.xml index 9c7b55ada..59d4013ca 100644 --- a/material/java/com/google/android/material/color/res/values-v35/tokens.xml +++ b/material/java/com/google/android/material/color/res/values-v35/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/values/extended_palette_tokens.xml b/material/java/com/google/android/material/color/res/values/extended_palette_tokens.xml index 7d91c297a..ac9620c0a 100644 --- a/material/java/com/google/android/material/color/res/values/extended_palette_tokens.xml +++ b/material/java/com/google/android/material/color/res/values/extended_palette_tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/color/res/values/tokens.xml b/material/java/com/google/android/material/color/res/values/tokens.xml index 942135c50..43c37319b 100644 --- a/material/java/com/google/android/material/color/res/values/tokens.xml +++ b/material/java/com/google/android/material/color/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + @@ -53,7 +53,6 @@ @color/m3_ref_palette_neutral4 @color/m3_ref_palette_neutral90 @color/m3_ref_palette_neutral20 - ?attr/colorPrimary @color/m3_ref_palette_neutral_variant60 @color/m3_ref_palette_neutral_variant30 @@ -103,7 +102,6 @@ @color/m3_ref_palette_neutral100 @color/m3_ref_palette_neutral20 @color/m3_ref_palette_neutral95 - ?attr/colorPrimary @color/m3_ref_palette_neutral_variant50 @color/m3_ref_palette_neutral_variant80 diff --git a/material/java/com/google/android/material/datepicker/res/values/tokens.xml b/material/java/com/google/android/material/datepicker/res/values/tokens.xml index 78dfb1217..c494808dc 100644 --- a/material/java/com/google/android/material/datepicker/res/values/tokens.xml +++ b/material/java/com/google/android/material/datepicker/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/dialog/res/values/themes_base.xml b/material/java/com/google/android/material/dialog/res/values/themes_base.xml index 9e8f148ec..a4c9dfa6a 100644 --- a/material/java/com/google/android/material/dialog/res/values/themes_base.xml +++ b/material/java/com/google/android/material/dialog/res/values/themes_base.xml @@ -287,9 +287,9 @@ @integer/m3_sys_motion_duration_extra_long4 @integer/m3_sys_motion_path - + true - @macro/m3_sys_color_light_surface_tint + ?attr/colorPrimary @style/ThemeOverlay.Material3.Dialog.Alert @@ -574,9 +574,9 @@ @integer/m3_sys_motion_duration_extra_long4 @integer/m3_sys_motion_path - + true - @macro/m3_sys_color_dark_surface_tint + ?attr/colorPrimary @style/ThemeOverlay.Material3.Dialog.Alert diff --git a/material/java/com/google/android/material/dialog/res/values/tokens.xml b/material/java/com/google/android/material/dialog/res/values/tokens.xml index 551c66bab..d1982e535 100644 --- a/material/java/com/google/android/material/dialog/res/values/tokens.xml +++ b/material/java/com/google/android/material/dialog/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/divider/res/values/tokens.xml b/material/java/com/google/android/material/divider/res/values/tokens.xml index b62dad10a..743a48661 100644 --- a/material/java/com/google/android/material/divider/res/values/tokens.xml +++ b/material/java/com/google/android/material/divider/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/elevation/res/values/tokens.xml b/material/java/com/google/android/material/elevation/res/values/tokens.xml index bdb2a4840..306358777 100644 --- a/material/java/com/google/android/material/elevation/res/values/tokens.xml +++ b/material/java/com/google/android/material/elevation/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/floatingtoolbar/res/values/tokens.xml b/material/java/com/google/android/material/floatingtoolbar/res/values/tokens.xml index 05a20d426..0d5594c9c 100644 --- a/material/java/com/google/android/material/floatingtoolbar/res/values/tokens.xml +++ b/material/java/com/google/android/material/floatingtoolbar/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/loadingindicator/res/values/tokens.xml b/material/java/com/google/android/material/loadingindicator/res/values/tokens.xml index c30548bfa..f40b5c6bf 100644 --- a/material/java/com/google/android/material/loadingindicator/res/values/tokens.xml +++ b/material/java/com/google/android/material/loadingindicator/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/materialswitch/res/values/dimens.xml b/material/java/com/google/android/material/materialswitch/res/values/dimens.xml index d9c475382..da60b0320 100644 --- a/material/java/com/google/android/material/materialswitch/res/values/dimens.xml +++ b/material/java/com/google/android/material/materialswitch/res/values/dimens.xml @@ -16,9 +16,9 @@ --> - 24dp + 32dp 16dp - 44dp - 24dp + @dimen/m3_comp_switch_track_width + @dimen/m3_comp_switch_track_height 16dp diff --git a/material/java/com/google/android/material/materialswitch/res/values/tokens.xml b/material/java/com/google/android/material/materialswitch/res/values/tokens.xml index e43409a4a..41e5caba7 100644 --- a/material/java/com/google/android/material/materialswitch/res/values/tokens.xml +++ b/material/java/com/google/android/material/materialswitch/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/menu/res/values/tokens.xml b/material/java/com/google/android/material/menu/res/values/tokens.xml index c6e19760d..1c81d2992 100644 --- a/material/java/com/google/android/material/menu/res/values/tokens.xml +++ b/material/java/com/google/android/material/menu/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/motion/res/values/tokens.xml b/material/java/com/google/android/material/motion/res/values/tokens.xml index f0739d6d6..241c2cb7b 100644 --- a/material/java/com/google/android/material/motion/res/values/tokens.xml +++ b/material/java/com/google/android/material/motion/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/navigation/res/values/tokens.xml b/material/java/com/google/android/material/navigation/res/values/tokens.xml index 0f1f887e4..d26595cf1 100644 --- a/material/java/com/google/android/material/navigation/res/values/tokens.xml +++ b/material/java/com/google/android/material/navigation/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/navigationrail/res/values/tokens.xml b/material/java/com/google/android/material/navigationrail/res/values/tokens.xml index 7cfc86d3c..38594cdc8 100644 --- a/material/java/com/google/android/material/navigationrail/res/values/tokens.xml +++ b/material/java/com/google/android/material/navigationrail/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/progressindicator/res/values/tokens.xml b/material/java/com/google/android/material/progressindicator/res/values/tokens.xml index fc72cc865..78d1e5066 100644 --- a/material/java/com/google/android/material/progressindicator/res/values/tokens.xml +++ b/material/java/com/google/android/material/progressindicator/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/radiobutton/res/values/tokens.xml b/material/java/com/google/android/material/radiobutton/res/values/tokens.xml index dce8ea161..1a489ed08 100644 --- a/material/java/com/google/android/material/radiobutton/res/values/tokens.xml +++ b/material/java/com/google/android/material/radiobutton/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/resources/res/values-v21/tokens.xml b/material/java/com/google/android/material/resources/res/values-v21/tokens.xml index f1ff95319..c635e293f 100644 --- a/material/java/com/google/android/material/resources/res/values-v21/tokens.xml +++ b/material/java/com/google/android/material/resources/res/values-v21/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/resources/res/values-v28/tokens.xml b/material/java/com/google/android/material/resources/res/values-v28/tokens.xml index dbeb8470d..a0db9b652 100644 --- a/material/java/com/google/android/material/resources/res/values-v28/tokens.xml +++ b/material/java/com/google/android/material/resources/res/values-v28/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/resources/res/values/tokens.xml b/material/java/com/google/android/material/resources/res/values/tokens.xml index 6e82bf628..44a7809d6 100644 --- a/material/java/com/google/android/material/resources/res/values/tokens.xml +++ b/material/java/com/google/android/material/resources/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/search/res/values/tokens.xml b/material/java/com/google/android/material/search/res/values/tokens.xml index 63eb7af57..dbb8e62de 100644 --- a/material/java/com/google/android/material/search/res/values/tokens.xml +++ b/material/java/com/google/android/material/search/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/shape/res/values/tokens.xml b/material/java/com/google/android/material/shape/res/values/tokens.xml index a880061ef..0c11f1c44 100644 --- a/material/java/com/google/android/material/shape/res/values/tokens.xml +++ b/material/java/com/google/android/material/shape/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/sidesheet/res/values/tokens.xml b/material/java/com/google/android/material/sidesheet/res/values/tokens.xml index 11c374854..a6bbdb66a 100644 --- a/material/java/com/google/android/material/sidesheet/res/values/tokens.xml +++ b/material/java/com/google/android/material/sidesheet/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/slider/BaseSlider.java b/material/java/com/google/android/material/slider/BaseSlider.java index b89c37438..6212302bc 100644 --- a/material/java/com/google/android/material/slider/BaseSlider.java +++ b/material/java/com/google/android/material/slider/BaseSlider.java @@ -3304,17 +3304,24 @@ private void positionLabel(TooltipDrawable label, float value) { } private void calculateLabelBounds(TooltipDrawable label, float value) { - int left = - trackSidePadding - + (int) (normalizeValue(value) * trackWidth) - - label.getIntrinsicWidth() / 2; - int right = left + label.getIntrinsicWidth(); + int left; + int right; int bottom; int top; if (isVertical() && !isRtl()) { + left = + trackSidePadding + + (int) (normalizeValue(value) * trackWidth) + - label.getIntrinsicHeight() / 2; + right = left + label.getIntrinsicHeight(); top = calculateTrackCenter() + (labelPadding + thumbHeight / 2); - bottom = top + label.getIntrinsicHeight(); + bottom = top + label.getIntrinsicWidth(); } else { + left = + trackSidePadding + + (int) (normalizeValue(value) * trackWidth) + - label.getIntrinsicWidth() / 2; + right = left + label.getIntrinsicWidth(); bottom = calculateTrackCenter() - (labelPadding + thumbHeight / 2); top = bottom - label.getIntrinsicHeight(); } @@ -3911,7 +3918,7 @@ protected boolean onPerformActionForVirtualView( } // Swap the increment if we're in RTL. - if (slider.isRtl() || slider.isVertical()) { + if (slider.isRtl()) { increment = -increment; } diff --git a/material/java/com/google/android/material/slider/res/values/tokens.xml b/material/java/com/google/android/material/slider/res/values/tokens.xml index 390ffb246..7918532a0 100644 --- a/material/java/com/google/android/material/slider/res/values/tokens.xml +++ b/material/java/com/google/android/material/slider/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/snackbar/res/values/tokens.xml b/material/java/com/google/android/material/snackbar/res/values/tokens.xml index 9a06809ce..45d09916a 100644 --- a/material/java/com/google/android/material/snackbar/res/values/tokens.xml +++ b/material/java/com/google/android/material/snackbar/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/tabs/res/values/tokens.xml b/material/java/com/google/android/material/tabs/res/values/tokens.xml index 30eb338b6..a1adfd937 100644 --- a/material/java/com/google/android/material/tabs/res/values/tokens.xml +++ b/material/java/com/google/android/material/tabs/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/textfield/res/values/tokens_dropdown_menu.xml b/material/java/com/google/android/material/textfield/res/values/tokens_dropdown_menu.xml index d922d07f8..725683dee 100644 --- a/material/java/com/google/android/material/textfield/res/values/tokens_dropdown_menu.xml +++ b/material/java/com/google/android/material/textfield/res/values/tokens_dropdown_menu.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/textfield/res/values/tokens_textfield.xml b/material/java/com/google/android/material/textfield/res/values/tokens_textfield.xml index ba7e564c6..d4ae7bc19 100644 --- a/material/java/com/google/android/material/textfield/res/values/tokens_textfield.xml +++ b/material/java/com/google/android/material/textfield/res/values/tokens_textfield.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/theme/res/values/themes_base.xml b/material/java/com/google/android/material/theme/res/values/themes_base.xml index f9c886717..432cd379e 100644 --- a/material/java/com/google/android/material/theme/res/values/themes_base.xml +++ b/material/java/com/google/android/material/theme/res/values/themes_base.xml @@ -301,9 +301,9 @@ @integer/m3_sys_motion_duration_extra_long4 @integer/m3_sys_motion_path - + true - @macro/m3_sys_color_light_surface_tint + ?attr/colorPrimary @style/ThemeOverlay.Material3.DynamicColors.Light @@ -591,9 +591,9 @@ @integer/m3_sys_motion_duration_extra_long4 @integer/m3_sys_motion_path - + true - @macro/m3_sys_color_dark_surface_tint + ?attr/colorPrimary @style/ThemeOverlay.Material3.DynamicColors.Dark diff --git a/material/java/com/google/android/material/timepicker/res/values/tokens.xml b/material/java/com/google/android/material/timepicker/res/values/tokens.xml index 6414c284e..e43f6df1e 100644 --- a/material/java/com/google/android/material/timepicker/res/values/tokens.xml +++ b/material/java/com/google/android/material/timepicker/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/tooltip/res/values/tokens.xml b/material/java/com/google/android/material/tooltip/res/values/tokens.xml index 1c24bc110..c1a625b20 100644 --- a/material/java/com/google/android/material/tooltip/res/values/tokens.xml +++ b/material/java/com/google/android/material/tooltip/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/material/java/com/google/android/material/typography/res/values/tokens.xml b/material/java/com/google/android/material/typography/res/values/tokens.xml index e749e6823..73f823f2e 100644 --- a/material/java/com/google/android/material/typography/res/values/tokens.xml +++ b/material/java/com/google/android/material/typography/res/values/tokens.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - + diff --git a/other_tool/android_studio_inspect/Inspect.xml b/other_tool/android_studio_inspect/Inspect.xml index 74b039484..a622723dc 100644 --- a/other_tool/android_studio_inspect/Inspect.xml +++ b/other_tool/android_studio_inspect/Inspect.xml @@ -134,6 +134,7 @@ + diff --git a/other_tool/camera_src.txt b/other_tool/camera_src.txt index 4e9cc2179..e1e83bd67 100644 --- a/other_tool/camera_src.txt +++ b/other_tool/camera_src.txt @@ -1,5 +1,5 @@ -curl --location https://maven.google.com/androidx/camera/camera-camera2/1.4.0/camera-camera2-1.4.0-sources.jar --output camera-camera2-1.4.0-sources.jar -curl --location https://maven.google.com/androidx/camera/camera-core/1.4.0/camera-core-1.4.0-sources.jar --output camera-core-1.4.0-sources.jar -curl --location https://maven.google.com/androidx/camera/camera-lifecycle/1.4.0/camera-lifecycle-1.4.0-sources.jar --output camera-lifecycle-1.4.0-sources.jar -curl --location https://maven.google.com/androidx/camera/camera-video/1.4.0/camera-video-1.4.0-sources.jar --output camera-video-1.4.0-sources.jar -curl --location https://maven.google.com/androidx/camera/camera-view/1.4.0/camera-view-1.4.0-sources.jar --output camera-view-1.4.0-sources.jar +curl --location https://maven.google.com/androidx/camera/camera-camera2/1.4.1/camera-camera2-1.4.1-sources.jar --output camera-camera2-1.4.1-sources.jar +curl --location https://maven.google.com/androidx/camera/camera-core/1.4.1/camera-core-1.4.1-sources.jar --output camera-core-1.4.1-sources.jar +curl --location https://maven.google.com/androidx/camera/camera-lifecycle/1.4.1/camera-lifecycle-1.4.1-sources.jar --output camera-lifecycle-1.4.1-sources.jar +curl --location https://maven.google.com/androidx/camera/camera-video/1.4.1/camera-video-1.4.1-sources.jar --output camera-video-1.4.1-sources.jar +curl --location https://maven.google.com/androidx/camera/camera-view/1.4.1/camera-view-1.4.1-sources.jar --output camera-view-1.4.1-sources.jar