【问题标题】:How to put a ULong to a ByteBuffer in Kotlin如何在 Kotlin 中将 ULong 放入 ByteBuffer
【发布时间】:2021-04-07 01:12:01
【问题描述】:

我只是在这篇文章中的答案How to convert a Data Class to ByteBuffer in Kotlin?

它按预期工作。问题是几乎所有数据类型都可以放置,除了无符号的一次。字节缓冲区有 putLong 等函数,但 putULong 没有。

任何提示都将不胜感激。

亲切的问候,

C.W.

【问题讨论】:

    标签: android kotlin bytebuffer ulong


    【解决方案1】:

    ULongLong之间是一一对应的,所以你可以将ULong转换成Long,放入缓冲区,读取时反之亦然。为方便起见,声明这些extension functions

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

    它们可以像get/put*()一样被调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-12
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多