From c17ceffc7776c35f7e701da19b5e13751b22a185 Mon Sep 17 00:00:00 2001 From: et-nik Date: Thu, 15 Nov 2018 10:45:43 +0300 Subject: [PATCH] Change key type. UINT32 -> INT32 --- src/BinnMap.php | 4 ++-- tests/BinnMapTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/BinnMap.php b/src/BinnMap.php index 1fe5566..a3704d8 100644 --- a/src/BinnMap.php +++ b/src/BinnMap.php @@ -99,7 +99,7 @@ private function _binnLoad($binnString) // Data $stopWhile = false; while ($pos < $this->size && !$stopWhile) { - $varKey = $this->unpack(self::BINN_UINT32, substr($binnString, $pos, 4)); + $varKey = $this->unpack(self::BINN_INT32, substr($binnString, $pos, 4)); $pos += 4; $varType = $this->unpack(self::BINN_UINT8, $binnString[$pos]); @@ -184,7 +184,7 @@ public function getBinnVal() $type = $arr[self::KEY_TYPE]; $storageType = $this->storageType($type); - $this->binnString .= $this->pack(self::BINN_UINT32, $key); + $this->binnString .= $this->pack(self::BINN_INT32, $key); if ($type === self::BINN_BOOL) { $this->binnString .= $arr[self::KEY_VAL] diff --git a/tests/BinnMapTest.php b/tests/BinnMapTest.php index 820db91..9f5be2e 100644 --- a/tests/BinnMapTest.php +++ b/tests/BinnMapTest.php @@ -52,4 +52,12 @@ public function testValidArray() $this->assertTrue(BinnMap::validArray([1 => 0, 2 => 2])); $this->assertFalse(BinnMap::validArray(['key' => 'val'])); } + + public function testNegativeKey() + { + $binn = new BinnMap(); + $array = [-2 => 543, -8 => 'test']; + $binnString = $binn->serialize($array); + $this->assertEquals($array, $binn->unserialize($binnString)); + } } \ No newline at end of file