Skip to content

Commit

Permalink
Finish negative-map
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed Nov 15, 2018
2 parents 38e4913 + c17ceff commit f6ac9bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/BinnMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 8 additions & 0 deletions tests/BinnMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit f6ac9bd

Please sign in to comment.