ulid-transform 1.4.0__tar.gz → 1.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,21 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: ulid-transform
3
- Version: 1.4.0
3
+ Version: 1.5.0
4
4
  Summary: Create and transform ULIDs
5
- License: MIT
5
+ License-Expression: MIT
6
+ License-File: LICENSE
6
7
  Author: J. Nick Koston
7
8
  Author-email: nick@koston.org
8
- Requires-Python: >=3.11,<4.0
9
+ Requires-Python: >=3.11
9
10
  Classifier: Development Status :: 5 - Production/Stable
10
11
  Classifier: Intended Audience :: Developers
11
- Classifier: License :: OSI Approved :: MIT License
12
12
  Classifier: Natural Language :: English
13
13
  Classifier: Operating System :: OS Independent
14
14
  Classifier: Programming Language :: Python :: 3
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
17
  Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
18
19
  Classifier: Topic :: Software Development :: Libraries
19
20
  Project-URL: Bug Tracker, https://github.com/bluetooth-devices/ulid-transform/issues
20
21
  Project-URL: Changelog, https://github.com/bluetooth-devices/ulid-transform/blob/main/CHANGELOG.md
@@ -1,20 +1,24 @@
1
- [tool.poetry]
1
+ [project]
2
2
  name = "ulid-transform"
3
- version = "1.4.0"
4
- description = "Create and transform ULIDs"
5
- authors = ["J. Nick Koston <nick@koston.org>"]
3
+ version = "1.5.0"
6
4
  license = "MIT"
5
+ description = "Create and transform ULIDs"
7
6
  readme = "README.md"
8
- repository = "https://github.com/bluetooth-devices/ulid-transform"
7
+ authors = [{ name = "J. Nick Koston", email = "nick@koston.org" }]
8
+ requires-python = ">=3.11"
9
+
10
+ [project.urls]
11
+ "Repository" = "https://github.com/bluetooth-devices/ulid-transform"
12
+ "Bug Tracker" = "https://github.com/bluetooth-devices/ulid-transform/issues"
13
+ "Changelog" = "https://github.com/bluetooth-devices/ulid-transform/blob/main/CHANGELOG.md"
14
+
15
+ [tool.poetry]
9
16
  classifiers = [
10
17
  "Development Status :: 5 - Production/Stable",
11
18
  "Intended Audience :: Developers",
12
19
  "Natural Language :: English",
13
20
  "Operating System :: OS Independent",
14
21
  "Topic :: Software Development :: Libraries",
15
- "Programming Language :: Python :: 3.11",
16
- "Programming Language :: Python :: 3.12",
17
- "Programming Language :: Python :: 3.13",
18
22
  ]
19
23
  packages = [
20
24
  { include = "ulid_transform", from = "src" },
@@ -24,19 +28,15 @@ packages = [
24
28
  generate-setup-file = true
25
29
  script = "build_ext.py"
26
30
 
27
- [tool.poetry.urls]
28
- "Bug Tracker" = "https://github.com/bluetooth-devices/ulid-transform/issues"
29
- "Changelog" = "https://github.com/bluetooth-devices/ulid-transform/blob/main/CHANGELOG.md"
30
-
31
31
  [tool.poetry.dependencies]
32
32
  python = "^3.11"
33
33
 
34
34
  [tool.poetry.group.dev.dependencies]
35
35
  pytest = ">=7,<9"
36
- pytest-cov = ">=3,<7"
36
+ pytest-cov = ">=3,<8"
37
37
  Cython = ">=3.0.5"
38
- setuptools = ">=65.4.1,<76.0.0"
39
- pytest-codspeed = "^3.1.2"
38
+ setuptools = ">=65.4.1,<80.0.0"
39
+ pytest-codspeed = ">=3.1.2,<5.0.0"
40
40
 
41
41
 
42
42
  [tool.poetry.group.benchmark.dependencies]
@@ -45,7 +45,7 @@ ulid2 = "^0.3.0"
45
45
  pytest-benchmark = ">=4,<6"
46
46
 
47
47
  [tool.semantic_release]
48
- version_toml = ["pyproject.toml:tool.poetry.version"]
48
+ version_toml = ["pyproject.toml:project.version"]
49
49
  version_variables = [
50
50
  "src/ulid_transform/__init__.py:__version__",
51
51
  ]
@@ -66,10 +66,6 @@ exclude_lines = [
66
66
  'if __name__ == "__main__":',
67
67
  ]
68
68
 
69
- [tool.isort]
70
- profile = "black"
71
- known_first_party = ["ulid_transform", "tests"]
72
-
73
69
  [tool.mypy]
74
70
  check_untyped_defs = true
75
71
  disallow_any_generics = true
@@ -92,6 +88,21 @@ allow_untyped_defs = true
92
88
  module = "bench.*"
93
89
  allow_untyped_defs = true
94
90
 
91
+ [tool.ruff.lint]
92
+ extend-select = [
93
+ "B",
94
+ "I",
95
+ "S",
96
+ "UP",
97
+ ]
98
+
99
+ [tool.ruff.lint.isort]
100
+ known-first-party = ["ulid_transform", "tests"]
101
+
102
+ [tool.ruff.lint.per-file-ignores]
103
+ "bench/*" = ["S101"]
104
+ "tests/*" = ["S101"]
105
+
95
106
  [build-system]
96
- requires = ['setuptools>=65.4.1', 'wheel', 'Cython>=3.0.2', "poetry-core>=1.0.0"]
107
+ requires = ['setuptools>=77.0', 'Cython>=3.0.2', "poetry-core>=2.1.0"]
97
108
  build-backend = "poetry.core.masonry.api"
@@ -12,7 +12,7 @@ package_data = \
12
12
 
13
13
  setup_kwargs = {
14
14
  'name': 'ulid-transform',
15
- 'version': '1.4.0',
15
+ 'version': '1.5.0',
16
16
  'description': 'Create and transform ULIDs',
17
17
  'long_description': '# Fast ULID transformations\n\n<p align="center">\n <a href="https://github.com/bluetooth-devices/ulid-transform/actions/workflows/ci.yml?query=branch%3Amain">\n <img src="https://img.shields.io/github/actions/workflow/status/bluetooth-devices/ulid-transform/ci.yml?branch=main&label=CI&logo=github&style=flat-square" alt="CI Status" >\n </a>\n <a href="https://codecov.io/gh/bluetooth-devices/ulid-transform">\n <img src="https://img.shields.io/codecov/c/github/bluetooth-devices/ulid-transform.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">\n </a>\n</p>\n<p align="center">\n <a href="https://python-poetry.org/">\n <img src="https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=" alt="Poetry">\n </a>\n <a href="https://github.com/ambv/black">\n <img src="https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square" alt="black">\n </a>\n <a href="https://github.com/pre-commit/pre-commit">\n <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">\n </a>\n <a href="https://codspeed.io/bluetooth-devices/ulid-transform"><img src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" alt="CodSpeed Badge"/></a>\n</p>\n<p align="center">\n <a href="https://pypi.org/project/ulid-transform/">\n <img src="https://img.shields.io/pypi/v/ulid-transform.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">\n </a>\n <img src="https://img.shields.io/pypi/pyversions/ulid-transform.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">\n <img src="https://img.shields.io/pypi/l/ulid-transform.svg?style=flat-square" alt="License">\n</p>\n\nCreate and transform ULIDs\n\nThis library will use the CPP implementation from https://github.com/suyash/ulid if cython is available, and will fallback to pure python if it is not.\n\n## Example\n\n```python\n>>> import ulid_transform\n>>> ulid_transform.ulid_hex()\n\'01869a2ea5fb0b43aa056293e47c0a35\'\n>>> ulid_transform.ulid_now()\n\'0001HZX0NW00GW0X476W5TVBFE\'\n>>> ulid_transform.ulid_at_time(1234)\n\'000000016JC62D620DGYNG2R8H\'\n>>> ulid_transform.ulid_to_bytes(\'0001HZX0NW00GW0X476W5TVBFE\')\nb\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\'\n>> ulid_transform.bytes_to_ulid(b"\\x01\\x86\\x99?\\xe8\\xf3\\x11\\xbc\\xed\\xef\\x86U.9\\x03z")\n\'01GTCKZT7K26YEVVW6AMQ3J0VT\'\n>>> ulid_transform.ulid_to_bytes_or_none(\'0001HZX0NW00GW0X476W5TVBFE\')\nb\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\'\n>>> ulid_transform.ulid_to_bytes_or_none(None)\n>>> ulid_transform.bytes_to_ulid_or_none(b\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\')\n\'0001HZX0NW00GW0X476W5TVBFE\'\n>>> ulid_transform.bytes_to_ulid_or_none(None)\n```\n\n## Installation\n\nInstall this via pip (or your favourite package manager):\n\n`pip install ulid-transform`\n\n## Contributors ✨\n\nThanks to https://github.com/suyash/ulid which provides the cython implementation guts.\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- prettier-ignore-start -->\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- markdownlint-disable -->\n<!-- markdownlint-enable -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n<!-- prettier-ignore-end -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## Credits\n\nThis package was created with\n[Copier](https://copier.readthedocs.io/) and the\n[browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)\nproject template.\n',
18
18
  'author': 'J. Nick Koston',
@@ -23,7 +23,7 @@ setup_kwargs = {
23
23
  'package_dir': package_dir,
24
24
  'packages': packages,
25
25
  'package_data': package_data,
26
- 'python_requires': '>=3.11,<4.0',
26
+ 'python_requires': '>=3.11',
27
27
  }
28
28
  from build_ext import *
29
29
  build(setup_kwargs)
@@ -1,4 +1,4 @@
1
- __version__ = "1.4.0"
1
+ __version__ = "1.5.0"
2
2
 
3
3
  try:
4
4
  from ._ulid_impl import (
@@ -0,0 +1,282 @@
1
+ #ifndef ULID_STRUCT_HH
2
+ #define ULID_STRUCT_HH
3
+
4
+ #include <array>
5
+ #include <chrono>
6
+ #include <cstdlib>
7
+ #include <ctime>
8
+ #include <functional>
9
+ #include <random>
10
+ #include <vector>
11
+
12
+ #if _MSC_VER > 0
13
+ typedef uint32_t rand_t;
14
+ #else
15
+ typedef uint8_t rand_t;
16
+ #endif
17
+
18
+ namespace ulid {
19
+
20
+ /**
21
+ * ULID is a 16 byte Universally Unique Lexicographically Sortable Identifier
22
+ * */
23
+ struct ULID {
24
+ uint8_t data[16];
25
+ };
26
+
27
+ /**
28
+ * EncodeTimestamp will encode the int64_t timestamp to the passed ulid
29
+ * */
30
+ inline void EncodeTimestamp(int64_t timestamp, ULID& ulid)
31
+ {
32
+ ulid.data[0] = static_cast<uint8_t>(timestamp >> 40);
33
+ ulid.data[1] = static_cast<uint8_t>(timestamp >> 32);
34
+ ulid.data[2] = static_cast<uint8_t>(timestamp >> 24);
35
+ ulid.data[3] = static_cast<uint8_t>(timestamp >> 16);
36
+ ulid.data[4] = static_cast<uint8_t>(timestamp >> 8);
37
+ ulid.data[5] = static_cast<uint8_t>(timestamp);
38
+ }
39
+
40
+ /**
41
+ * EncodeTime will encode the time point to the passed ulid
42
+ * */
43
+ inline void EncodeTime(std::chrono::time_point<std::chrono::system_clock> time_point, ULID& ulid)
44
+ {
45
+ auto time_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(time_point);
46
+ int64_t timestamp = time_ms.time_since_epoch().count();
47
+ EncodeTimestamp(timestamp, ulid);
48
+ }
49
+
50
+ /**
51
+ * EncodeTimeSystemClockNow will encode a ULID using the time obtained using
52
+ * std::chrono::system_clock::now() by taking the timestamp in milliseconds.
53
+ * */
54
+ inline void EncodeTimeSystemClockNow(ULID& ulid)
55
+ {
56
+ EncodeTime(std::chrono::system_clock::now(), ulid);
57
+ }
58
+
59
+ /**
60
+ * EncodeEntropyMt19937Fast will encode using std::mt19937
61
+ * with only 3 generated values.
62
+ * */
63
+ inline void EncodeEntropyMt19937Fast(ULID& ulid)
64
+ {
65
+ static thread_local std::mt19937 gen([]() {
66
+ // Use multiple entropy sources for seeding
67
+ std::array<uint32_t, 3> seed_data = {
68
+ static_cast<uint32_t>(std::chrono::high_resolution_clock::now().time_since_epoch().count()),
69
+ static_cast<uint32_t>(std::random_device {}()),
70
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&gen) & 0xFFFFFFFF)
71
+ };
72
+ std::seed_seq seed_seq(seed_data.begin(), seed_data.end());
73
+ return std::mt19937(seed_seq);
74
+ }());
75
+ uint64_t high = (static_cast<uint64_t>(gen()) << 32) | gen();
76
+ uint32_t low = gen();
77
+ ulid.data[6] = (high >> 40) & 0xFF;
78
+ ulid.data[7] = (high >> 32) & 0xFF;
79
+ ulid.data[8] = (high >> 24) & 0xFF;
80
+ ulid.data[9] = (high >> 16) & 0xFF;
81
+ ulid.data[10] = (high >> 8) & 0xFF;
82
+ ulid.data[11] = high & 0xFF;
83
+ ulid.data[12] = (low >> 24) & 0xFF;
84
+ ulid.data[13] = (low >> 16) & 0xFF;
85
+ ulid.data[14] = (low >> 8) & 0xFF;
86
+ ulid.data[15] = low & 0xFF;
87
+ }
88
+
89
+ /**
90
+ * Crockford's Base32
91
+ * */
92
+ static const char Encoding[33] = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
93
+
94
+ /**
95
+ * MarshalTo will marshal a ULID to the passed character array.
96
+ *
97
+ * Implementation taken directly from oklog/ulid
98
+ * (https://sourcegraph.com/github.com/oklog/ulid@0774f81f6e44af5ce5e91c8d7d76cf710e889ebb/-/blob/ulid.go#L162-190)
99
+ *
100
+ * timestamp:<br>
101
+ * dst[0]: first 3 bits of data[0]<br>
102
+ * dst[1]: last 5 bits of data[0]<br>
103
+ * dst[2]: first 5 bits of data[1]<br>
104
+ * dst[3]: last 3 bits of data[1] + first 2 bits of data[2]<br>
105
+ * dst[4]: bits 3-7 of data[2]<br>
106
+ * dst[5]: last bit of data[2] + first 4 bits of data[3]<br>
107
+ * dst[6]: last 4 bits of data[3] + first bit of data[4]<br>
108
+ * dst[7]: bits 2-6 of data[4]<br>
109
+ * dst[8]: last 2 bits of data[4] + first 3 bits of data[5]<br>
110
+ * dst[9]: last 5 bits of data[5]<br>
111
+ *
112
+ * entropy:
113
+ * follows similarly, except now all components are set to 5 bits.
114
+ * */
115
+ inline void MarshalTo(const ULID& ulid, char dst[26])
116
+ {
117
+ // 10 byte timestamp
118
+ dst[0] = Encoding[(ulid.data[0] & 224) >> 5];
119
+ dst[1] = Encoding[ulid.data[0] & 31];
120
+ dst[2] = Encoding[(ulid.data[1] & 248) >> 3];
121
+ dst[3] = Encoding[((ulid.data[1] & 7) << 2) | ((ulid.data[2] & 192) >> 6)];
122
+ dst[4] = Encoding[(ulid.data[2] & 62) >> 1];
123
+ dst[5] = Encoding[((ulid.data[2] & 1) << 4) | ((ulid.data[3] & 240) >> 4)];
124
+ dst[6] = Encoding[((ulid.data[3] & 15) << 1) | ((ulid.data[4] & 128) >> 7)];
125
+ dst[7] = Encoding[(ulid.data[4] & 124) >> 2];
126
+ dst[8] = Encoding[((ulid.data[4] & 3) << 3) | ((ulid.data[5] & 224) >> 5)];
127
+ dst[9] = Encoding[ulid.data[5] & 31];
128
+
129
+ // 16 bytes of entropy
130
+ dst[10] = Encoding[(ulid.data[6] & 248) >> 3];
131
+ dst[11] = Encoding[((ulid.data[6] & 7) << 2) | ((ulid.data[7] & 192) >> 6)];
132
+ dst[12] = Encoding[(ulid.data[7] & 62) >> 1];
133
+ dst[13] = Encoding[((ulid.data[7] & 1) << 4) | ((ulid.data[8] & 240) >> 4)];
134
+ dst[14] = Encoding[((ulid.data[8] & 15) << 1) | ((ulid.data[9] & 128) >> 7)];
135
+ dst[15] = Encoding[(ulid.data[9] & 124) >> 2];
136
+ dst[16] = Encoding[((ulid.data[9] & 3) << 3) | ((ulid.data[10] & 224) >> 5)];
137
+ dst[17] = Encoding[ulid.data[10] & 31];
138
+ dst[18] = Encoding[(ulid.data[11] & 248) >> 3];
139
+ dst[19] = Encoding[((ulid.data[11] & 7) << 2) | ((ulid.data[12] & 192) >> 6)];
140
+ dst[20] = Encoding[(ulid.data[12] & 62) >> 1];
141
+ dst[21] = Encoding[((ulid.data[12] & 1) << 4) | ((ulid.data[13] & 240) >> 4)];
142
+ dst[22] = Encoding[((ulid.data[13] & 15) << 1) | ((ulid.data[14] & 128) >> 7)];
143
+ dst[23] = Encoding[(ulid.data[14] & 124) >> 2];
144
+ dst[24] = Encoding[((ulid.data[14] & 3) << 3) | ((ulid.data[15] & 224) >> 5)];
145
+ dst[25] = Encoding[ulid.data[15] & 31];
146
+ }
147
+
148
+ /**
149
+ * MarshalBinaryTo will Marshal a ULID to the passed byte array
150
+ * */
151
+ inline void MarshalBinaryTo(const ULID& ulid, uint8_t dst[16])
152
+ {
153
+ // timestamp
154
+ dst[0] = ulid.data[0];
155
+ dst[1] = ulid.data[1];
156
+ dst[2] = ulid.data[2];
157
+ dst[3] = ulid.data[3];
158
+ dst[4] = ulid.data[4];
159
+ dst[5] = ulid.data[5];
160
+
161
+ // entropy
162
+ dst[6] = ulid.data[6];
163
+ dst[7] = ulid.data[7];
164
+ dst[8] = ulid.data[8];
165
+ dst[9] = ulid.data[9];
166
+ dst[10] = ulid.data[10];
167
+ dst[11] = ulid.data[11];
168
+ dst[12] = ulid.data[12];
169
+ dst[13] = ulid.data[13];
170
+ dst[14] = ulid.data[14];
171
+ dst[15] = ulid.data[15];
172
+ }
173
+
174
+ /**
175
+ * dec storesdecimal encodings for characters.
176
+ * 0xFF indicates invalid character.
177
+ * 48-57 are digits.
178
+ * 65-90 are capital alphabets.
179
+ * */
180
+ static const uint8_t dec[256] = {
181
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
182
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
183
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
184
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
185
+
186
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
187
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
188
+ /* 0 1 2 3 4 5 6 7 */
189
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
190
+ /* 8 9 */
191
+ 0x08, 0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
192
+
193
+ /* 10(A) 11(B) 12(C) 13(D) 14(E) 15(F) 16(G) */
194
+ 0xFF, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
195
+ /*17(H) 18(J) 19(K) 20(M) 21(N) */
196
+ 0x11, 0xFF, 0x12, 0x13, 0xFF, 0x14, 0x15, 0xFF,
197
+ /*22(P)23(Q)24(R) 25(S) 26(T) 27(V) 28(W) */
198
+ 0x16, 0x17, 0x18, 0x19, 0x1A, 0xFF, 0x1B, 0x1C,
199
+ /*29(X)30(Y)31(Z) */
200
+ 0x1D, 0x1E, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
201
+
202
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
203
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
204
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
205
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
206
+
207
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
208
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
209
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
210
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
211
+
212
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
213
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
214
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
215
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
216
+
217
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
218
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
219
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
220
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
221
+
222
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
223
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
224
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
225
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
226
+ };
227
+
228
+ /**
229
+ * UnmarshalFrom will unmarshal a ULID from the passed character array.
230
+ * */
231
+ inline void UnmarshalFrom(const char str[26], ULID& ulid)
232
+ {
233
+ // timestamp
234
+ ulid.data[0] = (dec[int(str[0])] << 5) | dec[int(str[1])];
235
+ ulid.data[1] = (dec[int(str[2])] << 3) | (dec[int(str[3])] >> 2);
236
+ ulid.data[2] = (dec[int(str[3])] << 6) | (dec[int(str[4])] << 1) | (dec[int(str[5])] >> 4);
237
+ ulid.data[3] = (dec[int(str[5])] << 4) | (dec[int(str[6])] >> 1);
238
+ ulid.data[4] = (dec[int(str[6])] << 7) | (dec[int(str[7])] << 2) | (dec[int(str[8])] >> 3);
239
+ ulid.data[5] = (dec[int(str[8])] << 5) | dec[int(str[9])];
240
+
241
+ // entropy
242
+ ulid.data[6] = (dec[int(str[10])] << 3) | (dec[int(str[11])] >> 2);
243
+ ulid.data[7] = (dec[int(str[11])] << 6) | (dec[int(str[12])] << 1) | (dec[int(str[13])] >> 4);
244
+ ulid.data[8] = (dec[int(str[13])] << 4) | (dec[int(str[14])] >> 1);
245
+ ulid.data[9] = (dec[int(str[14])] << 7) | (dec[int(str[15])] << 2) | (dec[int(str[16])] >> 3);
246
+ ulid.data[10] = (dec[int(str[16])] << 5) | dec[int(str[17])];
247
+ ulid.data[11] = (dec[int(str[18])] << 3) | (dec[int(str[19])] >> 2);
248
+ ulid.data[12] = (dec[int(str[19])] << 6) | (dec[int(str[20])] << 1) | (dec[int(str[21])] >> 4);
249
+ ulid.data[13] = (dec[int(str[21])] << 4) | (dec[int(str[22])] >> 1);
250
+ ulid.data[14] = (dec[int(str[22])] << 7) | (dec[int(str[23])] << 2) | (dec[int(str[24])] >> 3);
251
+ ulid.data[15] = (dec[int(str[24])] << 5) | dec[int(str[25])];
252
+ }
253
+
254
+ /**
255
+ * UnmarshalBinaryFrom will unmarshal a ULID from the passed byte array.
256
+ * */
257
+ inline void UnmarshalBinaryFrom(const uint8_t b[16], ULID& ulid)
258
+ {
259
+ // timestamp
260
+ ulid.data[0] = b[0];
261
+ ulid.data[1] = b[1];
262
+ ulid.data[2] = b[2];
263
+ ulid.data[3] = b[3];
264
+ ulid.data[4] = b[4];
265
+ ulid.data[5] = b[5];
266
+
267
+ // entropy
268
+ ulid.data[6] = b[6];
269
+ ulid.data[7] = b[7];
270
+ ulid.data[8] = b[8];
271
+ ulid.data[9] = b[9];
272
+ ulid.data[10] = b[10];
273
+ ulid.data[11] = b[11];
274
+ ulid.data[12] = b[12];
275
+ ulid.data[13] = b[13];
276
+ ulid.data[14] = b[14];
277
+ ulid.data[15] = b[15];
278
+ }
279
+
280
+ }; // namespace ulid
281
+
282
+ #endif // ULID_STRUCT_HH