From a49763dd739c3c68c4a8322896d594e926ac8e6b Mon Sep 17 00:00:00 2001 From: Zhineng Li Date: Mon, 5 Jan 2026 16:26:11 +0800 Subject: first commit --- src/Structure.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/Structure.php (limited to 'src/Structure.php') diff --git a/src/Structure.php b/src/Structure.php new file mode 100644 index 0000000..307397d --- /dev/null +++ b/src/Structure.php @@ -0,0 +1,62 @@ +sequenceCount > 1) { + throw new \LogicException('Only one sequence field is allowed in a structure.'); + } + + if ($this->currentOffset + $field->bits() > 63) { + throw new \OverflowException('Total structure size cannot exceed 63 bits.'); + } + + $this->fields[] = $field->setOffset($this->currentOffset); + $this->currentOffset += $field->bits(); + + return $this; + } + + /** + * The ID components. + * + * @return \Zhineng\Snowflake\Component[] + */ + public function components(): array + { + return $this->fields; + } + + /** + * The total size in bits. + */ + public function size(): int + { + return $this->currentOffset; + } +} -- cgit v1.2.3