Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization of UShort uses Int as a parameter instead of explicit Kotlin type #86

Open
Eragoneq opened this issue Apr 9, 2024 · 0 comments · May be fixed by #88
Open

Serialization of UShort uses Int as a parameter instead of explicit Kotlin type #86

Eragoneq opened this issue Apr 9, 2024 · 0 comments · May be fixed by #88

Comments

@Eragoneq
Copy link

Eragoneq commented Apr 9, 2024

When working on serialization of some packets I tried to improve the interface to use some more generic methods (will post another pull request) I have stumbled upon the code for UShort (de)serialization.

fun serializeUShort(value: Int): ByteArray {
val bytes = ByteArray(SERIALIZED_USHORT_SIZE)
bytes[1] = (value and 0xFF).toByte()
bytes[0] = ((value shr 8) and 0xFF).toByte()
return bytes
}
fun deserializeUShort(buffer: ByteArray, offset: Int = 0): Int {
return (((buffer[offset].toInt() and 0xFF) shl 8) or (buffer[offset + 1].toInt() and 0xFF))
}

For some reason these use usual Int as the input for the method instead of UShort which exists in the Kotlin stdlib. Is there any reasoning why the code does not follow the other examples? Types like UInt, ULong and UChar all use already existing types and that seems to be a weird exception.

@Eragoneq Eragoneq linked a pull request Apr 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant