You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fury.apache.org by "wywen (via GitHub)" <gi...@apache.org> on 2024/10/18 12:26:22 UTC

[PR] feat (kotlin): Add unsigned array support and tests for arrays and strings [fury]

wywen opened a new pull request, #1891:
URL: https://github.com/apache/fury/pull/1891

   <!--
   **Thanks for contributing to Fury.**
   
   **If this is your first time opening a PR on fury, you can refer to [CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).**
   
   Contribution Checklist
   
       - The **Apache Fury (incubating)** community has restrictions on the naming of pr titles. You can also find instructions in [CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).
   
       - Fury has a strong focus on performance. If the PR you submit will have an impact on performance, please benchmark it first and provide the benchmark result here.
   -->
   
   ## What does this PR do?
   
   This PR adds tests for serializing/deserializing:
   - Strings (same as Java)
   - Primitive arrays in Kotlin (same as Java)
   - Array<T> in kotlin (same as Java)
   - Unsigned arrays in kotlin - `UByteArray`, `UIntArray`, `UShortArray`, `ULongArray`
   
   Unsigned arrays in kotlin are currently marked experimental, and are subject to API changes (hence the annotations needed to suppress those warnings).
   
   These types are implemented as a view over the signed arrays e.g. UByteArray is a view over ByteArray with contents reinterpreted as UByte, so serializers. The current implementation delegate to existing serializers for corresponding signed types.
   
   The xlang type id is set to LIST for unsigned types.
   
   ## Related issues
   
   #683
   
   <!--
   Is there any related issue? Please attach here.
   
   - #xxxx0
   - #xxxx1
   - #xxxx2
   -->
   
   ## Does this PR introduce any user-facing change?
   
   Yes. Unsigned primitives no longer need to be registered for `fury-kotlin`.
   
   - [ ] Does this PR introduce any public API change?
   - [ ] Does this PR introduce any binary protocol compatibility change?
   
   ## Benchmark
   N/A
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org


Re: [PR] feat(kotlin): Add unsigned array support and tests for arrays and strings [fury]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #1891:
URL: https://github.com/apache/fury/pull/1891#discussion_r1806552579


##########
kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedArraySerializers.kt:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+@file:OptIn(ExperimentalUnsignedTypes::class)
+
+package org.apache.fury.serializer.kotlin
+
+import org.apache.fury.Fury
+import org.apache.fury.memory.MemoryBuffer
+import org.apache.fury.serializer.Serializer
+import org.apache.fury.type.Type
+
+abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
+    fury: Fury,
+    cls: Class<T>,
+    private val delegateClass: Class<T_Delegate>
+) : Serializer<T> (fury, cls) {
+
+    abstract fun toDelegateClass(value: T): T_Delegate
+
+    abstract fun fromDelegateClass(value: T_Delegate): T
+
+    override fun getXtypeId(): Short {
+        return (-Type.LIST.id).toShort()
+    }
+
+    override fun xwrite(buffer: MemoryBuffer, value: T) {
+        write(buffer, value)
+    }
+
+    override fun xread(buffer: MemoryBuffer): T {
+        return read(buffer)
+    }
+
+    override fun write(buffer: MemoryBuffer, value: T) {
+        val delegatingSerializer = fury.classResolver.getSerializer(delegateClass)

Review Comment:
   I guess all those unsiged array type are final 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org


Re: [PR] feat(kotlin): Add unsigned array support and tests for arrays and strings [fury]

Posted by "wywen (via GitHub)" <gi...@apache.org>.
wywen commented on code in PR #1891:
URL: https://github.com/apache/fury/pull/1891#discussion_r1807458617


##########
kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedArraySerializers.kt:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+@file:OptIn(ExperimentalUnsignedTypes::class)
+
+package org.apache.fury.serializer.kotlin
+
+import org.apache.fury.Fury
+import org.apache.fury.memory.MemoryBuffer
+import org.apache.fury.serializer.Serializer
+import org.apache.fury.type.Type
+
+abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
+    fury: Fury,
+    cls: Class<T>,
+    private val delegateClass: Class<T_Delegate>
+) : Serializer<T> (fury, cls) {
+
+    abstract fun toDelegateClass(value: T): T_Delegate
+
+    abstract fun fromDelegateClass(value: T_Delegate): T
+
+    override fun getXtypeId(): Short {
+        return (-Type.LIST.id).toShort()
+    }
+
+    override fun xwrite(buffer: MemoryBuffer, value: T) {
+        write(buffer, value)
+    }
+
+    override fun xread(buffer: MemoryBuffer): T {
+        return read(buffer)
+    }
+
+    override fun write(buffer: MemoryBuffer, value: T) {
+        val delegatingSerializer = fury.classResolver.getSerializer(delegateClass)

Review Comment:
   Yup those arrays are final! I made it a lazily initialized field.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org


Re: [PR] feat(kotlin): Add unsigned array support and tests for arrays and strings [fury]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #1891:
URL: https://github.com/apache/fury/pull/1891#discussion_r1807519870


##########
kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedArraySerializers.kt:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+@file:OptIn(ExperimentalUnsignedTypes::class)
+
+package org.apache.fury.serializer.kotlin
+
+import org.apache.fury.Fury
+import org.apache.fury.memory.MemoryBuffer
+import org.apache.fury.serializer.Serializer
+import org.apache.fury.type.Type
+
+abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
+    fury: Fury,
+    cls: Class<T>,
+    private val delegateClass: Class<T_Delegate>
+) : Serializer<T> (fury, cls) {
+
+    abstract fun toDelegateClass(value: T): T_Delegate
+
+    abstract fun fromDelegateClass(value: T_Delegate): T
+
+    override fun getXtypeId(): Short {
+        return (-Type.LIST.id).toShort()
+    }
+
+    override fun xwrite(buffer: MemoryBuffer, value: T) {
+        write(buffer, value)
+    }
+
+    override fun xread(buffer: MemoryBuffer): T {
+        return read(buffer)
+    }
+
+    override fun write(buffer: MemoryBuffer, value: T) {
+        val delegatingSerializer = fury.classResolver.getSerializer(delegateClass)

Review Comment:
   The lazy can be removed too



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org


Re: [PR] feat(kotlin): Add unsigned array support and tests for arrays and strings [fury]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #1891:
URL: https://github.com/apache/fury/pull/1891


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org


Re: [PR] feat(kotlin): Add unsigned array support and tests for arrays and strings [fury]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #1891:
URL: https://github.com/apache/fury/pull/1891#discussion_r1806552038


##########
kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedArraySerializers.kt:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+@file:OptIn(ExperimentalUnsignedTypes::class)
+
+package org.apache.fury.serializer.kotlin
+
+import org.apache.fury.Fury
+import org.apache.fury.memory.MemoryBuffer
+import org.apache.fury.serializer.Serializer
+import org.apache.fury.type.Type
+
+abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
+    fury: Fury,
+    cls: Class<T>,
+    private val delegateClass: Class<T_Delegate>
+) : Serializer<T> (fury, cls) {
+
+    abstract fun toDelegateClass(value: T): T_Delegate
+
+    abstract fun fromDelegateClass(value: T_Delegate): T
+
+    override fun getXtypeId(): Short {
+        return (-Type.LIST.id).toShort()
+    }
+
+    override fun xwrite(buffer: MemoryBuffer, value: T) {
+        write(buffer, value)
+    }
+
+    override fun xread(buffer: MemoryBuffer): T {
+        return read(buffer)
+    }
+
+    override fun write(buffer: MemoryBuffer, value: T) {
+        val delegatingSerializer = fury.classResolver.getSerializer(delegateClass)

Review Comment:
   Could we make this as a field of the DelegatingArraySerializer to reduce lookup cost?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org


Re: [PR] feat(kotlin): Add unsigned array support and tests for arrays and strings [fury]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #1891:
URL: https://github.com/apache/fury/pull/1891#discussion_r1806552579


##########
kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedArraySerializers.kt:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+@file:OptIn(ExperimentalUnsignedTypes::class)
+
+package org.apache.fury.serializer.kotlin
+
+import org.apache.fury.Fury
+import org.apache.fury.memory.MemoryBuffer
+import org.apache.fury.serializer.Serializer
+import org.apache.fury.type.Type
+
+abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
+    fury: Fury,
+    cls: Class<T>,
+    private val delegateClass: Class<T_Delegate>
+) : Serializer<T> (fury, cls) {
+
+    abstract fun toDelegateClass(value: T): T_Delegate
+
+    abstract fun fromDelegateClass(value: T_Delegate): T
+
+    override fun getXtypeId(): Short {
+        return (-Type.LIST.id).toShort()
+    }
+
+    override fun xwrite(buffer: MemoryBuffer, value: T) {
+        write(buffer, value)
+    }
+
+    override fun xread(buffer: MemoryBuffer): T {
+        return read(buffer)
+    }
+
+    override fun write(buffer: MemoryBuffer, value: T) {
+        val delegatingSerializer = fury.classResolver.getSerializer(delegateClass)

Review Comment:
   All those unsiged array type are final I guess



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org