diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:41:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:41:39 +0000 |
commit | fcfb5e62f95d625836328131cc5ca851182bcae4 (patch) | |
tree | 5309ef2284a82d61ece838d1dd1c97c09df152b8 /dependencies/pkg/mod/github.com/google | |
parent | Adding upstream version 1.1.1. (diff) | |
download | icingadb-fcfb5e62f95d625836328131cc5ca851182bcae4.tar.xz icingadb-fcfb5e62f95d625836328131cc5ca851182bcae4.zip |
Adding upstream version 1.2.0.upstream/1.2.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dependencies/pkg/mod/github.com/google')
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.3.0/.travis.yml | 9 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.3.0/CONTRIBUTING.md | 10 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/CODEOWNERS | 6 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/release-please.yml | 2 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/workflows/apidiff.yaml | 26 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/workflows/tests.yaml | 20 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CHANGELOG.md | 41 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CONTRIBUTING.md | 26 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CONTRIBUTORS (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/CONTRIBUTORS) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/LICENSE (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/LICENSE) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/README.md (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/README.md) | 10 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/dce.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/dce.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/doc.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/doc.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/go.mod (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/go.mod) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/hash.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/hash.go) | 6 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/json_test.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/json_test.go) | 51 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/marshal.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/marshal.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/node.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/node.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/node_js.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/node_js.go) | 2 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/node_net.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/node_net.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/null.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/null.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/null_test.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/null_test.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/seq_test.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/seq_test.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/sql.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/sql.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/sql_test.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/sql_test.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/time.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/time.go) | 21 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/util.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/util.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/uuid.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/uuid.go) | 89 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/uuid_test.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/uuid_test.go) | 228 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version1.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/version1.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version4.go (renamed from dependencies/pkg/mod/github.com/google/uuid@v1.3.0/version4.go) | 0 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version6.go | 56 | ||||
-rw-r--r-- | dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version7.go | 104 |
33 files changed, 669 insertions, 38 deletions
diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/.travis.yml b/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/.travis.yml deleted file mode 100644 index d8156a6..0000000 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: go - -go: - - 1.4.3 - - 1.5.3 - - tip - -script: - - go test -v ./... diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/CONTRIBUTING.md b/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/CONTRIBUTING.md deleted file mode 100644 index 04fdf09..0000000 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/CONTRIBUTING.md +++ /dev/null @@ -1,10 +0,0 @@ -# How to contribute - -We definitely welcome patches and contribution to this project! - -### Legal requirements - -In order to protect both you and ourselves, you will need to sign the -[Contributor License Agreement](https://cla.developers.google.com/clas). - -You may have already signed it for other Google projects. diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/CODEOWNERS b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/CODEOWNERS new file mode 100644 index 0000000..91a5fa3 --- /dev/null +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/CODEOWNERS @@ -0,0 +1,6 @@ +# Code owners file. +# This file controls who is tagged for review for any given pull request. + +# For syntax help see: +# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax +* @google/go-uuid-contributors diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/release-please.yml b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/release-please.yml new file mode 100644 index 0000000..e1bcc3c --- /dev/null +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/release-please.yml @@ -0,0 +1,2 @@ +handleGHRelease: true +releaseType: go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/workflows/apidiff.yaml b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/workflows/apidiff.yaml new file mode 100644 index 0000000..37c0b5f --- /dev/null +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/workflows/apidiff.yaml @@ -0,0 +1,26 @@ +--- +name: apidiff +on: + pull_request: + branches: + - master +permissions: + contents: read +jobs: + compat: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v4 + with: + go-version: 1.21 + - run: go install golang.org/x/exp/cmd/apidiff@latest + - uses: actions/checkout@v3 + with: + ref: master + - run: apidiff -w uuid.baseline . + - uses: actions/checkout@v3 + with: + clean: false + - run: | + apidiff -incompatible uuid.baseline . > diff.txt + cat diff.txt && ! [ -s diff.txt ] diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/workflows/tests.yaml b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/workflows/tests.yaml new file mode 100644 index 0000000..138397c --- /dev/null +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/.github/workflows/tests.yaml @@ -0,0 +1,20 @@ +--- +name: tests +on: + pull_request: + branches: + - master +permissions: + contents: read +jobs: + unit-tests: + strategy: + matrix: + go-version: [1.19, 1.20.x, 1.21] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - run: go test -v ./... diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CHANGELOG.md b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CHANGELOG.md new file mode 100644 index 0000000..7ec5ac7 --- /dev/null +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CHANGELOG.md @@ -0,0 +1,41 @@ +# Changelog + +## [1.6.0](https://github.com/google/uuid/compare/v1.5.0...v1.6.0) (2024-01-16) + + +### Features + +* add Max UUID constant ([#149](https://github.com/google/uuid/issues/149)) ([c58770e](https://github.com/google/uuid/commit/c58770eb495f55fe2ced6284f93c5158a62e53e3)) + + +### Bug Fixes + +* fix typo in version 7 uuid documentation ([#153](https://github.com/google/uuid/issues/153)) ([016b199](https://github.com/google/uuid/commit/016b199544692f745ffc8867b914129ecb47ef06)) +* Monotonicity in UUIDv7 ([#150](https://github.com/google/uuid/issues/150)) ([a2b2b32](https://github.com/google/uuid/commit/a2b2b32373ff0b1a312b7fdf6d38a977099698a6)) + +## [1.5.0](https://github.com/google/uuid/compare/v1.4.0...v1.5.0) (2023-12-12) + + +### Features + +* Validate UUID without creating new UUID ([#141](https://github.com/google/uuid/issues/141)) ([9ee7366](https://github.com/google/uuid/commit/9ee7366e66c9ad96bab89139418a713dc584ae29)) + +## [1.4.0](https://github.com/google/uuid/compare/v1.3.1...v1.4.0) (2023-10-26) + + +### Features + +* UUIDs slice type with Strings() convenience method ([#133](https://github.com/google/uuid/issues/133)) ([cd5fbbd](https://github.com/google/uuid/commit/cd5fbbdd02f3e3467ac18940e07e062be1f864b4)) + +### Fixes + +* Clarify that Parse's job is to parse but not necessarily validate strings. (Documents current behavior) + +## [1.3.1](https://github.com/google/uuid/compare/v1.3.0...v1.3.1) (2023-08-18) + + +### Bug Fixes + +* Use .EqualFold() to parse urn prefixed UUIDs ([#118](https://github.com/google/uuid/issues/118)) ([574e687](https://github.com/google/uuid/commit/574e6874943741fb99d41764c705173ada5293f0)) + +## Changelog diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CONTRIBUTING.md b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CONTRIBUTING.md new file mode 100644 index 0000000..a502fdc --- /dev/null +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CONTRIBUTING.md @@ -0,0 +1,26 @@ +# How to contribute + +We definitely welcome patches and contribution to this project! + +### Tips + +Commits must be formatted according to the [Conventional Commits Specification](https://www.conventionalcommits.org). + +Always try to include a test case! If it is not possible or not necessary, +please explain why in the pull request description. + +### Releasing + +Commits that would precipitate a SemVer change, as described in the Conventional +Commits Specification, will trigger [`release-please`](https://github.com/google-github-actions/release-please-action) +to create a release candidate pull request. Once submitted, `release-please` +will create a release. + +For tips on how to work with `release-please`, see its documentation. + +### Legal requirements + +In order to protect both you and ourselves, you will need to sign the +[Contributor License Agreement](https://cla.developers.google.com/clas). + +You may have already signed it for other Google projects. diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/CONTRIBUTORS b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CONTRIBUTORS index b4bb97f..b4bb97f 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/CONTRIBUTORS +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/CONTRIBUTORS diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/LICENSE b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/LICENSE index 5dc6826..5dc6826 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/LICENSE +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/LICENSE diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/README.md b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/README.md index f765a46..3e9a618 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/README.md +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/README.md @@ -1,6 +1,6 @@ -# uuid ![build status](https://travis-ci.org/google/uuid.svg?branch=master) +# uuid The uuid package generates and inspects UUIDs based on -[RFC 4122](http://tools.ietf.org/html/rfc4122) +[RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122) and DCE 1.1: Authentication and Security Services. This package is based on the github.com/pborman/uuid package (previously named @@ -9,10 +9,12 @@ a UUID is a 16 byte array rather than a byte slice. One loss due to this change is the ability to represent an invalid UUID (vs a NIL UUID). ###### Install -`go get github.com/google/uuid` +```sh +go get github.com/google/uuid +``` ###### Documentation -[![GoDoc](https://godoc.org/github.com/google/uuid?status.svg)](http://godoc.org/github.com/google/uuid) +[![Go Reference](https://pkg.go.dev/badge/github.com/google/uuid.svg)](https://pkg.go.dev/github.com/google/uuid) Full `go doc` style documentation for the package can be viewed online without installing this package by using the GoDoc site here: diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/dce.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/dce.go index fa820b9..fa820b9 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/dce.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/dce.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/doc.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/doc.go index 5b8a4b9..5b8a4b9 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/doc.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/doc.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/go.mod b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/go.mod index fc84cd7..fc84cd7 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/go.mod +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/go.mod diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/hash.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/hash.go index b404f4b..dc60082 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/hash.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/hash.go @@ -17,6 +17,12 @@ var ( NameSpaceOID = Must(Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")) NameSpaceX500 = Must(Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")) Nil UUID // empty UUID, all zeros + + // The Max UUID is special form of UUID that is specified to have all 128 bits set to 1. + Max = UUID{ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + } ) // NewHash returns a new UUID derived from the hash of space concatenated with diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/json_test.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/json_test.go index 245f91e..34241d5 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/json_test.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/json_test.go @@ -31,6 +31,57 @@ func TestJSON(t *testing.T) { } } +func TestJSONUnmarshal(t *testing.T) { + type S struct { + ID1 UUID + ID2 UUID `json:"ID2,omitempty"` + } + + testCases := map[string]struct { + data []byte + expectedError error + expectedResult UUID + }{ + "success": { + data: []byte(`{"ID1": "f47ac10b-58cc-0372-8567-0e02b2c3d479"}`), + expectedError: nil, + expectedResult: testUUID, + }, + "zero": { + data: []byte(`{"ID1": "00000000-0000-0000-0000-000000000000"}`), + expectedError: nil, + expectedResult: Nil, + }, + "null": { + data: []byte(`{"ID1": null}`), + expectedError: nil, + expectedResult: Nil, + }, + "empty": { + data: []byte(`{"ID1": ""}`), + expectedError: invalidLengthError{len: 0}, + expectedResult: Nil, + }, + "omitempty": { + data: []byte(`{"ID2": ""}`), + expectedError: invalidLengthError{len: 0}, + expectedResult: Nil, + }, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + var s S + if err := json.Unmarshal(tc.data, &s); err != tc.expectedError { + t.Errorf("unexpected error: got %v, want %v", err, tc.expectedError) + } + if !reflect.DeepEqual(s.ID1, tc.expectedResult) { + t.Errorf("got %#v, want %#v", s.ID1, tc.expectedResult) + } + }) + } +} + func BenchmarkUUID_MarshalJSON(b *testing.B) { x := &struct { UUID UUID `json:"uuid"` diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/marshal.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/marshal.go index 14bd340..14bd340 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/marshal.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/marshal.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/node.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/node.go index d651a2b..d651a2b 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/node.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/node.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/node_js.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/node_js.go index 24b78ed..b2a0bc8 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/node_js.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/node_js.go @@ -7,6 +7,6 @@ package uuid // getHardwareInterface returns nil values for the JS version of the code. -// This remvoves the "net" dependency, because it is not used in the browser. +// This removes the "net" dependency, because it is not used in the browser. // Using the "net" library inflates the size of the transpiled JS code by 673k bytes. func getHardwareInterface(name string) (string, []byte) { return "", nil } diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/node_net.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/node_net.go index 0cbbcdd..0cbbcdd 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/node_net.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/node_net.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/null.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/null.go index d7fcbf2..d7fcbf2 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/null.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/null.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/null_test.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/null_test.go index c6e5e69..c6e5e69 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/null_test.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/null_test.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/seq_test.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/seq_test.go index 4f6c549..4f6c549 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/seq_test.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/seq_test.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/sql.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/sql.go index 2e02ec0..2e02ec0 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/sql.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/sql.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/sql_test.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/sql_test.go index 1803dfd..1803dfd 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/sql_test.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/sql_test.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/time.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/time.go index e6ef06c..c351129 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/time.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/time.go @@ -108,12 +108,23 @@ func setClockSequence(seq int) { } // Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in -// uuid. The time is only defined for version 1 and 2 UUIDs. +// uuid. The time is only defined for version 1, 2, 6 and 7 UUIDs. func (uuid UUID) Time() Time { - time := int64(binary.BigEndian.Uint32(uuid[0:4])) - time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32 - time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48 - return Time(time) + var t Time + switch uuid.Version() { + case 6: + time := binary.BigEndian.Uint64(uuid[:8]) // Ignore uuid[6] version b0110 + t = Time(time) + case 7: + time := binary.BigEndian.Uint64(uuid[:8]) + t = Time((time>>16)*10000 + g1582ns100) + default: // forward compatible + time := int64(binary.BigEndian.Uint32(uuid[0:4])) + time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32 + time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48 + t = Time(time) + } + return t } // ClockSequence returns the clock sequence encoded in uuid. diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/util.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/util.go index 5ea6c73..5ea6c73 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/util.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/util.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/uuid.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/uuid.go index a57207a..5232b48 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/uuid.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/uuid.go @@ -56,11 +56,15 @@ func IsInvalidLengthError(err error) bool { return ok } -// Parse decodes s into a UUID or returns an error. Both the standard UUID -// forms of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and -// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as the -// Microsoft encoding {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} and the raw hex -// encoding: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. +// Parse decodes s into a UUID or returns an error if it cannot be parsed. Both +// the standard UUID forms defined in RFC 4122 +// (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and +// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) are decoded. In addition, +// Parse accepts non-standard strings such as the raw hex encoding +// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx and 38 byte "Microsoft style" encodings, +// e.g. {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}. Only the middle 36 bytes are +// examined in the latter case. Parse should not be used to validate strings as +// it parses non-standard encodings as indicated above. func Parse(s string) (UUID, error) { var uuid UUID switch len(s) { @@ -69,7 +73,7 @@ func Parse(s string) (UUID, error) { // urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx case 36 + 9: - if strings.ToLower(s[:9]) != "urn:uuid:" { + if !strings.EqualFold(s[:9], "urn:uuid:") { return uuid, fmt.Errorf("invalid urn prefix: %q", s[:9]) } s = s[9:] @@ -101,7 +105,8 @@ func Parse(s string) (UUID, error) { 9, 11, 14, 16, 19, 21, - 24, 26, 28, 30, 32, 34} { + 24, 26, 28, 30, 32, 34, + } { v, ok := xtob(s[x], s[x+1]) if !ok { return uuid, errors.New("invalid UUID format") @@ -117,7 +122,7 @@ func ParseBytes(b []byte) (UUID, error) { switch len(b) { case 36: // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx case 36 + 9: // urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - if !bytes.Equal(bytes.ToLower(b[:9]), []byte("urn:uuid:")) { + if !bytes.EqualFold(b[:9], []byte("urn:uuid:")) { return uuid, fmt.Errorf("invalid urn prefix: %q", b[:9]) } b = b[9:] @@ -145,7 +150,8 @@ func ParseBytes(b []byte) (UUID, error) { 9, 11, 14, 16, 19, 21, - 24, 26, 28, 30, 32, 34} { + 24, 26, 28, 30, 32, 34, + } { v, ok := xtob(b[x], b[x+1]) if !ok { return uuid, errors.New("invalid UUID format") @@ -180,6 +186,59 @@ func Must(uuid UUID, err error) UUID { return uuid } +// Validate returns an error if s is not a properly formatted UUID in one of the following formats: +// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +// {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} +// It returns an error if the format is invalid, otherwise nil. +func Validate(s string) error { + switch len(s) { + // Standard UUID format + case 36: + + // UUID with "urn:uuid:" prefix + case 36 + 9: + if !strings.EqualFold(s[:9], "urn:uuid:") { + return fmt.Errorf("invalid urn prefix: %q", s[:9]) + } + s = s[9:] + + // UUID enclosed in braces + case 36 + 2: + if s[0] != '{' || s[len(s)-1] != '}' { + return fmt.Errorf("invalid bracketed UUID format") + } + s = s[1 : len(s)-1] + + // UUID without hyphens + case 32: + for i := 0; i < len(s); i += 2 { + _, ok := xtob(s[i], s[i+1]) + if !ok { + return errors.New("invalid UUID format") + } + } + + default: + return invalidLengthError{len(s)} + } + + // Check for standard UUID format + if len(s) == 36 { + if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' { + return errors.New("invalid UUID format") + } + for _, x := range []int{0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34} { + if _, ok := xtob(s[x], s[x+1]); !ok { + return errors.New("invalid UUID format") + } + } + } + + return nil +} + // String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx // , or "" if uuid is invalid. func (uuid UUID) String() string { @@ -292,3 +351,15 @@ func DisableRandPool() { poolMu.Lock() poolPos = randPoolSize } + +// UUIDs is a slice of UUID types. +type UUIDs []UUID + +// Strings returns a string slice containing the string form of each UUID in uuids. +func (uuids UUIDs) Strings() []string { + var uuidStrs = make([]string, len(uuids)) + for i, uuid := range uuids { + uuidStrs[i] = uuid.String() + } + return uuidStrs +} diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/uuid_test.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/uuid_test.go index e98d0fe..c1c6001 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/uuid_test.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/uuid_test.go @@ -6,6 +6,7 @@ package uuid import ( "bytes" + "errors" "fmt" "os" "runtime" @@ -73,6 +74,9 @@ var tests = []test{ {"f47ac10b58cc037285670e02b2c3d479", 0, RFC4122, true}, {"f47ac10b58cc037285670e02b2c3d4790", 0, Invalid, false}, {"f47ac10b58cc037285670e02b2c3d47", 0, Invalid, false}, + + {"01ee836c-e7c9-619d-929a-525400475911", 6, RFC4122, true}, + {"018bd12c-58b0-7683-8a5b-8752d0e86651", 7, RFC4122, true}, } var constants = []struct { @@ -569,6 +573,67 @@ func TestIsWrongLength(t *testing.T) { } } +func FuzzParse(f *testing.F) { + for _, tt := range tests { + f.Add(tt.in) + f.Add(strings.ToUpper(tt.in)) + } + f.Fuzz(func(t *testing.T, in string) { + Parse(in) + }) +} + +func FuzzParseBytes(f *testing.F) { + for _, tt := range tests { + f.Add([]byte(tt.in)) + } + f.Fuzz(func(t *testing.T, in []byte) { + ParseBytes(in) + }) +} + +func FuzzFromBytes(f *testing.F) { + // Copied from TestFromBytes. + f.Add([]byte{ + 0x7d, 0x44, 0x48, 0x40, + 0x9d, 0xc0, + 0x11, 0xd1, + 0xb2, 0x45, + 0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2, + }) + f.Fuzz(func(t *testing.T, in []byte) { + FromBytes(in) + }) +} + +// TestValidate checks various scenarios for the Validate function +func TestValidate(t *testing.T) { + testCases := []struct { + name string + input string + expect error + }{ + {"Valid UUID", "123e4567-e89b-12d3-a456-426655440000", nil}, + {"Valid UUID with URN", "urn:uuid:123e4567-e89b-12d3-a456-426655440000", nil}, + {"Valid UUID with Braces", "{123e4567-e89b-12d3-a456-426655440000}", nil}, + {"Valid UUID No Hyphens", "123e4567e89b12d3a456426655440000", nil}, + {"Invalid UUID", "invalid-uuid", errors.New("invalid UUID length: 12")}, + {"Invalid Length", "123", fmt.Errorf("invalid UUID length: %d", len("123"))}, + {"Invalid URN Prefix", "urn:test:123e4567-e89b-12d3-a456-426655440000", fmt.Errorf("invalid urn prefix: %q", "urn:test:")}, + {"Invalid Brackets", "[123e4567-e89b-12d3-a456-426655440000]", fmt.Errorf("invalid bracketed UUID format")}, + {"Invalid UUID Format", "12345678gabc1234abcd1234abcd1234", fmt.Errorf("invalid UUID format")}, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := Validate(tc.input) + if (err != nil) != (tc.expect != nil) || (err != nil && err.Error() != tc.expect.Error()) { + t.Errorf("Validate(%q) = %v, want %v", tc.input, err, tc.expect) + } + }) + } +} + var asString = "f47ac10b-58cc-0372-8567-0e02b2c3d479" var asBytes = []byte(asString) @@ -700,3 +765,166 @@ func BenchmarkUUID_NewPooled(b *testing.B) { } }) } + +func BenchmarkUUIDs_Strings(b *testing.B) { + uuid1, err := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479") + if err != nil { + b.Fatal(err) + } + uuid2, err := Parse("7d444840-9dc0-11d1-b245-5ffdce74fad2") + if err != nil { + b.Fatal(err) + } + uuids := UUIDs{uuid1, uuid2} + for i := 0; i < b.N; i++ { + uuids.Strings() + } +} + +func TestVersion6(t *testing.T) { + uuid1, err := NewV6() + if err != nil { + t.Fatalf("could not create UUID: %v", err) + } + uuid2, err := NewV6() + if err != nil { + t.Fatalf("could not create UUID: %v", err) + } + + if uuid1 == uuid2 { + t.Errorf("%s:duplicate uuid", uuid1) + } + if v := uuid1.Version(); v != 6 { + t.Errorf("%s: version %s expected 6", uuid1, v) + } + if v := uuid2.Version(); v != 6 { + t.Errorf("%s: version %s expected 6", uuid2, v) + } + n1 := uuid1.NodeID() + n2 := uuid2.NodeID() + if !bytes.Equal(n1, n2) { + t.Errorf("Different nodes %x != %x", n1, n2) + } + t1 := uuid1.Time() + t2 := uuid2.Time() + q1 := uuid1.ClockSequence() + q2 := uuid2.ClockSequence() + + switch { + case t1 == t2 && q1 == q2: + t.Error("time stopped") + case t1 > t2 && q1 == q2: + t.Error("time reversed") + case t1 < t2 && q1 != q2: + t.Error("clock sequence changed unexpectedly") + } +} + +// uuid v7 time is only unix milliseconds, so +// uuid1.Time() == uuid2.Time() is right, but uuid1 must != uuid2 +func TestVersion7(t *testing.T) { + SetRand(nil) + m := make(map[string]bool) + for x := 1; x < 128; x++ { + uuid, err := NewV7() + if err != nil { + t.Fatalf("could not create UUID: %v", err) + } + s := uuid.String() + if m[s] { + t.Errorf("NewV7 returned duplicated UUID %s", s) + } + m[s] = true + if v := uuid.Version(); v != 7 { + t.Errorf("UUID of version %s", v) + } + if uuid.Variant() != RFC4122 { + t.Errorf("UUID is variant %d", uuid.Variant()) + } + } +} + +// uuid v7 time is only unix milliseconds, so +// uuid1.Time() == uuid2.Time() is right, but uuid1 must != uuid2 +func TestVersion7_pooled(t *testing.T) { + SetRand(nil) + EnableRandPool() + defer DisableRandPool() + + m := make(map[string]bool) + for x := 1; x < 128; x++ { + uuid, err := NewV7() + if err != nil { + t.Fatalf("could not create UUID: %v", err) + } + s := uuid.String() + if m[s] { + t.Errorf("NewV7 returned duplicated UUID %s", s) + } + m[s] = true + if v := uuid.Version(); v != 7 { + t.Errorf("UUID of version %s", v) + } + if uuid.Variant() != RFC4122 { + t.Errorf("UUID is variant %d", uuid.Variant()) + } + } +} + +func TestVersion7FromReader(t *testing.T) { + myString := "8059ddhdle77cb52" + r := bytes.NewReader([]byte(myString)) + _, err := NewV7FromReader(r) + if err != nil { + t.Errorf("failed generating UUID from a reader") + } + _, err = NewV7FromReader(r) + if err == nil { + t.Errorf("expecting an error as reader has no more bytes. Got uuid. NewV7FromReader may not be using the provided reader") + } +} + +func TestVersion7Monotonicity(t *testing.T) { + length := 10000 + u1 := Must(NewV7()).String() + for i := 0; i < length; i++ { + u2 := Must(NewV7()).String() + if u2 <= u1 { + t.Errorf("monotonicity failed at #%d: %s(next) < %s(before)", i, u2, u1) + break + } + u1 = u2 + } +} + +type fakeRand struct{} + +func (g fakeRand) Read(bs []byte) (int, error) { + for i, _ := range bs { + bs[i] = 0x88 + } + return len(bs), nil +} + +func TestVersion7MonotonicityStrict(t *testing.T) { + timeNow = func() time.Time { + return time.Date(2008, 8, 8, 8, 8, 8, 8, time.UTC) + } + defer func() { + timeNow = time.Now + }() + + SetRand(fakeRand{}) + defer SetRand(nil) + + length := 100000 // > 3906 + u1 := Must(NewV7()).String() + for i := 0; i < length; i++ { + u2 := Must(NewV7()).String() + if u2 <= u1 { + t.Errorf("monotonicity failed at #%d: %s(next) < %s(before)", i, u2, u1) + break + } + u1 = u2 + } +} diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/version1.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version1.go index 4631096..4631096 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/version1.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version1.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/version4.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version4.go index 7697802..7697802 100644 --- a/dependencies/pkg/mod/github.com/google/uuid@v1.3.0/version4.go +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version4.go diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version6.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version6.go new file mode 100644 index 0000000..339a959 --- /dev/null +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version6.go @@ -0,0 +1,56 @@ +// Copyright 2023 Google Inc. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package uuid + +import "encoding/binary" + +// UUID version 6 is a field-compatible version of UUIDv1, reordered for improved DB locality. +// It is expected that UUIDv6 will primarily be used in contexts where there are existing v1 UUIDs. +// Systems that do not involve legacy UUIDv1 SHOULD consider using UUIDv7 instead. +// +// see https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-03#uuidv6 +// +// NewV6 returns a Version 6 UUID based on the current NodeID and clock +// sequence, and the current time. If the NodeID has not been set by SetNodeID +// or SetNodeInterface then it will be set automatically. If the NodeID cannot +// be set NewV6 set NodeID is random bits automatically . If clock sequence has not been set by +// SetClockSequence then it will be set automatically. If GetTime fails to +// return the current NewV6 returns Nil and an error. +func NewV6() (UUID, error) { + var uuid UUID + now, seq, err := GetTime() + if err != nil { + return uuid, err + } + + /* + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | time_high | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | time_mid | time_low_and_version | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |clk_seq_hi_res | clk_seq_low | node (0-1) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | node (2-5) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + + binary.BigEndian.PutUint64(uuid[0:], uint64(now)) + binary.BigEndian.PutUint16(uuid[8:], seq) + + uuid[6] = 0x60 | (uuid[6] & 0x0F) + uuid[8] = 0x80 | (uuid[8] & 0x3F) + + nodeMu.Lock() + if nodeID == zeroID { + setNodeInterface("") + } + copy(uuid[10:], nodeID[:]) + nodeMu.Unlock() + + return uuid, nil +} diff --git a/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version7.go b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version7.go new file mode 100644 index 0000000..3167b64 --- /dev/null +++ b/dependencies/pkg/mod/github.com/google/uuid@v1.6.0/version7.go @@ -0,0 +1,104 @@ +// Copyright 2023 Google Inc. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package uuid + +import ( + "io" +) + +// UUID version 7 features a time-ordered value field derived from the widely +// implemented and well known Unix Epoch timestamp source, +// the number of milliseconds seconds since midnight 1 Jan 1970 UTC, leap seconds excluded. +// As well as improved entropy characteristics over versions 1 or 6. +// +// see https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-03#name-uuid-version-7 +// +// Implementations SHOULD utilize UUID version 7 over UUID version 1 and 6 if possible. +// +// NewV7 returns a Version 7 UUID based on the current time(Unix Epoch). +// Uses the randomness pool if it was enabled with EnableRandPool. +// On error, NewV7 returns Nil and an error +func NewV7() (UUID, error) { + uuid, err := NewRandom() + if err != nil { + return uuid, err + } + makeV7(uuid[:]) + return uuid, nil +} + +// NewV7FromReader returns a Version 7 UUID based on the current time(Unix Epoch). +// it use NewRandomFromReader fill random bits. +// On error, NewV7FromReader returns Nil and an error. +func NewV7FromReader(r io.Reader) (UUID, error) { + uuid, err := NewRandomFromReader(r) + if err != nil { + return uuid, err + } + + makeV7(uuid[:]) + return uuid, nil +} + +// makeV7 fill 48 bits time (uuid[0] - uuid[5]), set version b0111 (uuid[6]) +// uuid[8] already has the right version number (Variant is 10) +// see function NewV7 and NewV7FromReader +func makeV7(uuid []byte) { + /* + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | unix_ts_ms | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | unix_ts_ms | ver | rand_a (12 bit seq) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |var| rand_b | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | rand_b | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + _ = uuid[15] // bounds check + + t, s := getV7Time() + + uuid[0] = byte(t >> 40) + uuid[1] = byte(t >> 32) + uuid[2] = byte(t >> 24) + uuid[3] = byte(t >> 16) + uuid[4] = byte(t >> 8) + uuid[5] = byte(t) + + uuid[6] = 0x70 | (0x0F & byte(s>>8)) + uuid[7] = byte(s) +} + +// lastV7time is the last time we returned stored as: +// +// 52 bits of time in milliseconds since epoch +// 12 bits of (fractional nanoseconds) >> 8 +var lastV7time int64 + +const nanoPerMilli = 1000000 + +// getV7Time returns the time in milliseconds and nanoseconds / 256. +// The returned (milli << 12 + seq) is guarenteed to be greater than +// (milli << 12 + seq) returned by any previous call to getV7Time. +func getV7Time() (milli, seq int64) { + timeMu.Lock() + defer timeMu.Unlock() + + nano := timeNow().UnixNano() + milli = nano / nanoPerMilli + // Sequence number is between 0 and 3906 (nanoPerMilli>>8) + seq = (nano - milli*nanoPerMilli) >> 8 + now := milli<<12 + seq + if now <= lastV7time { + now = lastV7time + 1 + milli = now >> 12 + seq = now & 0xfff + } + lastV7time = now + return milli, seq +} |