0

I just the answer in this post How to convert a Data Class to ByteBuffer in Kotlin?

And it works as expected. The problem is that nearly all data types are possible to put except the unsigned once. There are putLong etc. functions for bytebuffers but not for putULong.

Any hint would be apreciated.

Kind regards,

C.W.

abeat
  • 31
  • 2

1 Answers1

0

There is an one-to-one correspondence between ULong and Long, so you can convert ULong to Long, put that into the buffer, and vice versa when reading. For convenience, declare these extension functions:

fun ByteBuffer.putULong(value: ULong): ByteBuffer = putLong(value.toLong())

fun ByteBuffer.getULong(): ULong = getLong().toULong()

and they can be called just like get/put*().

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487