Generate UUID for each track (necessary for synchronization).

Fixes #294.
This commit is contained in:
Dennis Guse
2020-06-28 18:09:08 +02:00
parent ecdb509371
commit c9869bab0e
8 changed files with 166 additions and 40 deletions
@@ -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();
}
}