Files
fullstack-starter/docs/工具箱端-授权对接指南/utils/DistributedIdUtil.kt

13 lines
433 B
Kotlin

package top.tangyh.lamp.filing.utils
object DistributedIdUtil {
fun generateId(platformId: Long, localId: Long): Long {
require(platformId in 0..0xFFFF) { "platformId must be 0-65535" }
val safeLocalId = localId and 0xFFFFFFFFFFFF
return (platformId shl 48) or safeLocalId
}
fun parsePlatform(id: Long): Long = id ushr 48
fun parseLocal(id: Long): Long = id and 0xFFFFFFFFFFFF
}