Push latest work
This commit is contained in:
parent
852ddf8972
commit
a9abed7279
2 changed files with 42 additions and 20 deletions
|
@ -13,16 +13,31 @@ class UUID {
|
|||
LSB = lsb.abs();
|
||||
}
|
||||
|
||||
UUID.fromBytes(List<int> bytes) {
|
||||
int msb = 0;
|
||||
int lsb = 0;
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < 8; ++i) {
|
||||
msb = msb << 8 | bytes[i] & 255;
|
||||
}
|
||||
|
||||
for (i = 8; i < 16; ++i) {
|
||||
lsb = lsb << 8 | bytes[i] & 255;
|
||||
}
|
||||
|
||||
this.MSB = msb;
|
||||
this.LSB = lsb;
|
||||
}
|
||||
|
||||
static final UUID ZERO = UUID.generate(0);
|
||||
|
||||
/// Validates whether the given [uuid] is a valid UUID.
|
||||
static bool validate(String uuid) {
|
||||
try {
|
||||
parse(uuid);
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (uuid.length == ((16 * 2) + 4)) {
|
||||
return true; // Likely is true. This is just a surface level check
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses the given [uuid] string and returns a UUID object.
|
||||
|
@ -114,21 +129,12 @@ class UUID {
|
|||
var msb = layer.readUnsignedLong();
|
||||
var lsb = layer.readUnsignedLong();
|
||||
|
||||
layer.clear();
|
||||
layer.writeUnsignedLong(lsb);
|
||||
layer.resetPosition();
|
||||
|
||||
csv = "";
|
||||
for (int byte in layer.readBytes(8)) {
|
||||
csv += "0x${byte.toRadixString(16)}, ";
|
||||
}
|
||||
|
||||
print("BYTES CSV: ${csv}");
|
||||
|
||||
if (msb < 0) print("Most significant bit is negative! ${msb}");
|
||||
if (lsb < 0) print("Least significant bit is negative! ${lsb}");
|
||||
|
||||
print("Forming UUID using MSB-LSB - ${msb} - ${lsb}");
|
||||
layer.resetPosition();
|
||||
return UUID.fromBytes(layer.readBytes(16));
|
||||
return UUID(msb, lsb);
|
||||
}
|
||||
case 4:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue