add(Constant::make('machine_id', 10)); $this->assertCount(1, $struct->components()); } public function testAddMultipleFields(): void { $struct = new Structure; $struct->add(Constant::make('machine_id', 5)); $struct->add(Constant::make('datacenter_id', 5)); $this->assertCount(2, $struct->components()); } public function testOffsetsAreCalculatedCorrectly(): void { $struct = new Structure; $struct->add($machineId = Constant::make('machine_id', 5)); $struct->add($dataCenterId = Constant::make('datacenter_id', 5)); $this->assertSame(0, $machineId->offset()); $this->assertSame(5, $dataCenterId->offset()); } public function testSizeResolution(): void { $struct = new Structure; $struct->add(Constant::make('machine_id', 5)); $struct->add(Constant::make('datacenter_id', 5)); $this->assertSame(10, $struct->size()); } public function testAtMostOneSequenceIsAllowed(): void { $struct = new Structure; $struct->add(Sequence::make('seq1', 12)); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Only one sequence field is allowed in a structure.'); $struct->add(Sequence::make('seq2', 12)); } public function testTotalSizeCannotExceed63Bits(): void { $struct = new Structure; $struct->add(Constant::make('field1', 32)); $struct->add(Constant::make('field2', 31)); $this->expectException(\OverflowException::class); $this->expectExceptionMessage('Total structure size cannot exceed 63 bits.'); $struct->add(Constant::make('field3', 1)); } }