-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2024, Nordic Semiconductor | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Kotlin Util Library | ||
|
||
This repository contains set of Kotlin-only (no Android dependency) libraries for various purposes. | ||
|
||
## Data | ||
|
||
Kotlin library for data manipulation. | ||
|
||
It contains extension methods for `ByteArray` allowing to read numbers in big-endian and little-endian | ||
order in various formats, bit operators for `Byte` and `Short` and methods for converting UUIDs to | ||
and from `ByteArray`. | ||
|
||
#### Setting up | ||
|
||
Add the following to your `build.gradle` file: | ||
|
||
```groovy | ||
implementation "no.nordicsemi.kotlin:data:1.0.0" | ||
``` | ||
|
||
### Reading Integers | ||
|
||
```kotlin | ||
val array = byteArrayOf(0x87.toByte(), 0x65, 0x43, 0x21, 0x21, 0x43, 0x65, 0x87.toByte()) | ||
val int1 = array.getInt(offset = 0, format = IntFormat.INT32, order = ByteOrder.BIG_ENDIAN) | ||
val int2 = array.getInt(offset = 4, format = IntFormat.INT32, order = ByteOrder.LITTLE_ENDIAN) | ||
assertEquals(-2023406815, int1) | ||
assertEquals(-2023406815, int2) | ||
``` | ||
|
||
### Reading Floats | ||
|
||
Supported types include: | ||
* IEEE 754 single and double precision | ||
* IEEE 11073 32-bit and 16-bit | ||
|
||
```kotlin | ||
val array = byteArrayOf(0xFF.toByte(), 0x00, 0x01, 0x6C, 0x97.toByte(), 0x0D, 0x00, 0xFE.toByte()) | ||
val float1 = array.getFloat(0, FloatFormat.IEEE_11073_32_BIT, ByteOrder.BIG_ENDIAN) | ||
val float2 = array.getFloat(4, FloatFormat.IEEE_11073_32_BIT, ByteOrder.LITTLE_ENDIAN) | ||
assertEquals(36.4f, float1) | ||
assertEquals(34.79f, float2) | ||
``` | ||
|
||
### Bit operators | ||
|
||
The library also contains extension methods for `Byte` allowing to perform bitwise operations. | ||
|
||
```kotlin | ||
val value = 0b1010_1001.toByte() | ||
assertTrue(value hasAllBitsSet 0b1000_0001) | ||
``` | ||
|
||
```kotlin | ||
val value = 0b1010_1001.toByte() | ||
assertTrue(value hasBitSet 0) | ||
assertFalse(value hasBitCleared 0) | ||
``` | ||
|
||
```kotlin | ||
val value = 0b1010_1001_1010_1001.toShort() | ||
assertEquals(0b1101_0100_1101_0100.toShort(), value shr 1) | ||
assertEquals(0b1111_1010_1001_1010.toShort(), value shr 4) | ||
``` | ||
|
||
### UUID | ||
|
||
The library also contains extension methods for `ByteArray` allowing to convert UUIDs to and from `ByteArray`. | ||
|
||
```kotlin | ||
val uuid1 = UUID.randomUUID() | ||
val array = uuid1.toByteArray(order = ByteOrder.BIG_ENDIAN) | ||
val uuid2 = array.toUuid(order = ByteOrder.BIG_ENDIAN) | ||
assertEquals(uuid, uuid2) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
plugins { | ||
alias(libs.plugins.kotlin.jvm) apply false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2024, Nordic Semiconductor | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this list of | ||
* conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list | ||
* of conditions and the following disclaimer in the documentation and/or other materials | ||
* provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software without specific prior | ||
* written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
plugins { | ||
alias(libs.plugins.kotlin.jvm) | ||
alias(libs.plugins.nordic.nexus.kotlin) | ||
} | ||
|
||
group = "no.nordicsemi.kotlin" | ||
|
||
nordicNexusPublishing { | ||
POM_ARTIFACT_ID = "data" | ||
POM_NAME = "Kotlin data utils." | ||
|
||
POM_DESCRIPTION = "Set of extension methods for writing and reading bytes to and from a ByteArray." | ||
POM_URL = "https://github.com/NordicSemiconductor/Kotlin-Util-Library" | ||
POM_SCM_URL = "https://github.com/NordicSemiconductor/Kotlin-Util-Library" | ||
POM_SCM_CONNECTION = "scm:[email protected]:NordicSemiconductor/Kotlin-Util-Library.git" | ||
POM_SCM_DEV_CONNECTION = "scm:[email protected]:NordicSemiconductor/Kotlin-Util-Library.git" | ||
} | ||
|
||
dependencies { | ||
testImplementation(libs.kotlin.junit) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:/Users/alno/AppData/Local/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle.kts. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |