UnlauncherAppsSerializer.kt 1.0 KB

12345678910111213141516171819202122232425262728
  1. package com.sduduzog.slimlauncher.datasource.apps
  2. import androidx.datastore.core.CorruptionException
  3. import androidx.datastore.core.Serializer
  4. import com.google.protobuf.InvalidProtocolBufferException
  5. import com.jkuester.unlauncher.datastore.UnlauncherApps
  6. import java.io.InputStream
  7. import java.io.OutputStream
  8. /**
  9. * Serializer for the [UnlauncherApps] object defined in quick_button_preferences.proto.
  10. */
  11. object UnlauncherAppsSerializer : Serializer<UnlauncherApps> {
  12. override val defaultValue: UnlauncherApps = UnlauncherApps.getDefaultInstance()
  13. @Suppress("BlockingMethodInNonBlockingContext")
  14. override suspend fun readFrom(input: InputStream): UnlauncherApps {
  15. try {
  16. return UnlauncherApps.parseFrom(input)
  17. } catch (exception: InvalidProtocolBufferException) {
  18. throw CorruptionException("Cannot read proto.", exception)
  19. }
  20. }
  21. @Suppress("BlockingMethodInNonBlockingContext")
  22. override suspend fun writeTo(t: UnlauncherApps, output: OutputStream) =
  23. t.writeTo(output)
  24. }