mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-04 10:23:06 +02:00
Generate UUID for each track (necessary for synchronization).
Fixes #294.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package de.dennisguse.opentracks.util;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDUtils {
|
||||
|
||||
public static UUID fromBytes(byte[] bytes) {
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
|
||||
long mostSignificant = byteBuffer.getLong();
|
||||
long lestSignificant = byteBuffer.getLong();
|
||||
return new UUID(mostSignificant, lestSignificant);
|
||||
}
|
||||
|
||||
public static byte[] toBytes(@NonNull UUID uuid) {
|
||||
ByteBuffer byteBuffer = ByteBuffer.allocate(16);
|
||||
byteBuffer.putLong(uuid.getMostSignificantBits());
|
||||
byteBuffer.putLong(uuid.getLeastSignificantBits());
|
||||
return byteBuffer.array();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user