This implementation converts byte arrays to strings, which are much easier to test. Prerequisitesīefore writing tests, add the encodeToString method with the default implementation to the Base64Encoder interface, which is defined in commonMain/kotlin/org/jetbrains/base64/Base64.kt. To save time on testing, you can write common tests that will be executed on all platforms instead of testing each platform separately. Now when you have actual implementations of the Base64Factory object for all platforms, it's time to test your multiplatform library. Private val BASE64_INVERSE_ALPHABET = IntArray(256) Private val BASE64_ALPHABET: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" In commonMain/kotlin, create a new 64 directory.Ĭreate the Base64.kt file in the new directory.ĭefine the Base64Encoder interface that converts bytes to the Base64 format: ![]() The wizard will create a sample multiplatform library with the following structure: Write cross-platform codeĭefine the classes and interfaces you are going to implement in the common code. Specify the JDK, which is required for developing Kotlin projects. In the left-hand panel, select Kotlin Multiplatform.Įnter a project name, then in the Multiplatform section select Library as the project template.īy default, your project will use Gradle with Kotlin DSL as the build system. In IntelliJ IDEA, select File | New | Project. Download and install the latest version of IntelliJ IDEA with the latest Kotlin plugin. You can complete this tutorial on any operating system. You can find a similar project in this GitHub repository. You will also test your code using common tests, and then publish the library to your local Maven repository. You will use different ways to implement the conversion to the Base64 format on different platforms:įor Kotlin/Native – your own implementation. It can be used on Kotlin/JVM, Kotlin/JS, and any available Kotlin/Native platform. ![]() This library converts raw data – strings and byte arrays – to the Base64 format. In this tutorial, you will learn how to create a multiplatform library for JVM, JS, and Native platforms, write common tests for all platforms, and publish the library to a local Maven repository.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |