-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generic UUID v8 so you can customize it. Cleanup tests based on n…
…ew specs, and update URLs of the RFC
- Loading branch information
Showing
7 changed files
with
155 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'dart:typed_data'; | ||
import 'package:uuid/data.dart'; | ||
|
||
import 'parsing.dart'; | ||
|
||
class UuidV8Generic { | ||
final GlobalOptions? goptions; | ||
|
||
const UuidV8Generic({this.goptions}); | ||
|
||
/// V8Generic() Generates a time-based version 8 UUID | ||
/// | ||
/// Takes in 128 bits (16 bytes) of custom data, and produces a valid V8 uuid. | ||
/// Bits 48-51 and bits 64-65 will be modified to create a valid uuid. | ||
/// | ||
/// https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis#name-uuid-version-8 | ||
/// | ||
/// 0 10 20 30 | ||
/// 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F | ||
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
/// | custom_a | | ||
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
/// | custom_a | ver | custom_b | | ||
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
/// |var| custom_c | | ||
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
/// | custom_c | | ||
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
/// | ||
/// 48 bits - custom_a | ||
/// 4 bits - version | ||
/// 12 bits - custom_b | ||
/// 2 bits - variant | ||
/// 62 bits - custom_c | ||
String generate({V8GenericOptions? options}) { | ||
var buf = Uint8List(16); | ||
|
||
List<int> data = | ||
options?.data ?? goptions?.rng?.generate() ?? List<int>.filled(16, 0); | ||
|
||
buf.setRange(0, 16, data); | ||
buf.setRange(6, 7, [buf.getRange(6, 7).last & 0x0f | 0x80]); | ||
buf.setRange(8, 9, [buf.getRange(8, 9).last & 0x3f | 0x80]); | ||
|
||
return UuidParsing.unparse(buf); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters