Skip to content

Commit

Permalink
Change Kotlin's bytes type from UByteArray to ByteArray
Browse files Browse the repository at this point in the history
This reflects the fact that `ByteArray` is a lot more common than
`UByteArray`.
  • Loading branch information
heinrich5991 committed May 23, 2023
1 parent e5c8f75 commit 8d82ffb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
8 changes: 4 additions & 4 deletions fixtures/coverall/tests/bindings/test_coverall.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import uniffi.coverall.*
createSomeDict().use { d ->
assert(d.text == "text")
assert(d.maybeText == "maybe_text")
assert(d.someBytes.contentEquals("some_bytes".toByteArray(Charsets.UTF_8).toUByteArray()))
assert(d.maybeSomeBytes.contentEquals("maybe_some_bytes".toByteArray(Charsets.UTF_8).toUByteArray()))
assert(d.someBytes.contentEquals("some_bytes".toByteArray(Charsets.UTF_8)))
assert(d.maybeSomeBytes.contentEquals("maybe_some_bytes".toByteArray(Charsets.UTF_8)))
assert(d.aBool)
assert(d.maybeABool == false)
assert(d.unsigned8 == 1.toUByte())
Expand Down Expand Up @@ -44,7 +44,7 @@ createSomeDict().use { d ->
createNoneDict().use { d ->
assert(d.text == "text")
assert(d.maybeText == null)
assert(d.someBytes.contentEquals("some_bytes".toByteArray(Charsets.UTF_8).toUByteArray()))
assert(d.someBytes.contentEquals("some_bytes".toByteArray(Charsets.UTF_8)))
assert(d.maybeSomeBytes == null)
assert(d.aBool)
assert(d.maybeABool == null)
Expand Down Expand Up @@ -251,5 +251,5 @@ assert(d.integer == 42UL)

// Test bytes
Coveralls("test_bytes").use { coveralls ->
assert(coveralls.reverse("123".toByteArray(Charsets.UTF_8).toUByteArray()).toByteArray().toString(Charsets.UTF_8) == "321")
assert(coveralls.reverse("123".toByteArray(Charsets.UTF_8)).toString(Charsets.UTF_8) == "321")
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ macro_rules! impl_code_type_for_primitive {

impl_code_type_for_primitive!(BooleanCodeType, "Boolean");
impl_code_type_for_primitive!(StringCodeType, "String");
impl_code_type_for_primitive!(BytesCodeType, "UByteArray");
impl_code_type_for_primitive!(BytesCodeType, "ByteArray");
impl_code_type_for_primitive!(Int8CodeType, "Byte");
impl_code_type_for_primitive!(Int16CodeType, "Short");
impl_code_type_for_primitive!(Int32CodeType, "Int");
Expand Down
15 changes: 15 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/ByteArrayHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public object FfiConverterByteArray: FfiConverterRustBuffer<ByteArray> {
override fun read(buf: ByteBuffer): ByteArray {
val len = buf.getInt()
val byteArr = ByteArray(len)
buf.get(byteArr)
return byteArr
}
override fun allocationSize(value: ByteArray): Int {
return 4 + value.size
}
override fun write(value: ByteArray, buf: ByteBuffer) {
buf.putInt(value.size)
buf.put(value)
}
}
2 changes: 1 addition & 1 deletion uniffi_bindgen/src/bindings/kotlin/templates/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{%- include "StringHelper.kt" %}
{%- when Type::Bytes %}
{%- include "UByteArrayHelper.kt" %}
{%- include "ByteArrayHelper.kt" %}
{%- when Type::Enum(name) %}
{% include "EnumTemplate.kt" %}
Expand Down
16 changes: 0 additions & 16 deletions uniffi_bindgen/src/bindings/kotlin/templates/UByteArrayHelper.kt

This file was deleted.

4 changes: 0 additions & 4 deletions uniffi_bindgen/src/bindings/kotlin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ pub fn run_script(
.arg("-J-ea")
// Our test scripts should not produce any warnings.
.arg("-Werror")
// Allow `UByteArray`
.arg("-opt-in=kotlin.ExperimentalUnsignedTypes")
.arg("-script")
.arg(script_path)
.args(if args.is_empty() {
Expand Down Expand Up @@ -105,8 +103,6 @@ fn build_jar(
command
// Our generated bindings should not produce any warnings; fail tests if they do.
.arg("-Werror")
// Allow `UByteArray`
.arg("-opt-in=kotlin.ExperimentalUnsignedTypes")
.arg("-d")
.arg(&jar_file)
.arg("-classpath")
Expand Down

0 comments on commit 8d82ffb

Please sign in to comment.