(uuid: Uuid)
| 321 | /// Returns an error if the UUID contains invalid values. |
| 322 | #[expect(clippy::big_endian_bytes, reason = "We want to be deterministic")] |
| 323 | pub fn decode(uuid: Uuid) -> Result<Self, Report<[ParseGlobalIdError]>> { |
| 324 | let bytes = *uuid.as_bytes(); |
| 325 | |
| 326 | // run_id |
| 327 | let run_id = RunId(u16::from_be_bytes([bytes[0], bytes[1]])); |
| 328 | |
| 329 | // stage_id |
| 330 | let stage_id = StageId(u16::from_be_bytes([bytes[2], bytes[3]])); |
| 331 | |
| 332 | // shard_id |
| 333 | let shard_id = ShardId(u16::from_be_bytes([bytes[4], bytes[5]])); |
| 334 | |
| 335 | // producer = hi4 | lo4 |
| 336 | let hi4 = bytes[6] & 0x0F; |
| 337 | let lo4 = bytes[8] & 0x0F; |
| 338 | let producer = |
| 339 | ProducerId::from_u8((hi4 << 4) | lo4).change_context(ParseGlobalIdError::Producer); |
| 340 | |
| 341 | // retry |
| 342 | let retry = bytes[7]; |
| 343 | |
| 344 | // provenance (bits 5..4) |
| 345 | let provenance = match (bytes[8] >> 4) & 0b11 { |
| 346 | 0b00 => Provenance::Integration, |
| 347 | 0b01 => Provenance::Benchmark, |
| 348 | 0b10 => Provenance::Staging, |
| 349 | _ => Provenance::Unknown, |
| 350 | }; |
| 351 | |
| 352 | // scope |
| 353 | let scope = Scope::from_u8(bytes[9]).change_context(ParseGlobalIdError::Scope); |
| 354 | |
| 355 | // sub_scope |
| 356 | let sub_scope = SubScope::from_u16(u16::from_be_bytes([bytes[10], bytes[11]])) |
| 357 | .change_context(ParseGlobalIdError::SubScope); |
| 358 | |
| 359 | // local_id |
| 360 | let local_id = LocalId(u32::from_be_bytes([ |
| 361 | bytes[12], bytes[13], bytes[14], bytes[15], |
| 362 | ])); |
| 363 | |
| 364 | let (producer, scope, sub_scope) = (producer, scope, sub_scope).try_collect()?; |
| 365 | |
| 366 | Ok(Self { |
| 367 | run_id, |
| 368 | stage_id, |
| 369 | shard_id, |
| 370 | local_id, |
| 371 | provenance, |
| 372 | producer, |
| 373 | scope, |
| 374 | sub_scope, |
| 375 | retry, |
| 376 | }) |
| 377 | } |
| 378 | |
| 379 | #[must_use] |
| 380 | pub fn rng(self) -> impl Rng { |
nothing calls this directly
no test coverage detected