-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastien Giroux
committed
Jun 9, 2012
1 parent
a6ac35f
commit 0b12afa
Showing
9 changed files
with
167 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace phpcassa\Schema\DataType; | ||
|
||
use phpcassa\Schema\DataType\LongType; | ||
use phpcassa\Schema\DataType\Serialized; | ||
|
||
/** | ||
* Stores a date as a number of milliseconds since the unix epoch. | ||
* | ||
* @package phpcassa\Schema\DataType | ||
*/ | ||
class DateType extends LongType implements Serialized { | ||
|
||
public function pack($value, $is_name=true, $slice_end=null, $is_data=false) | ||
{ | ||
if (false !== strpos($value, ' ')) { | ||
list($usec, $sec) = explode(' ', $value); | ||
$value = $sec + $usec; | ||
} else if ($is_name && $is_data) { | ||
$value = unserialize($value); | ||
} | ||
|
||
$value = floor($value * 1e3); | ||
return parent::pack($value); | ||
} | ||
|
||
public function unpack($data, $handle_serialize=true) | ||
{ | ||
$value = parent::unpack($data, false) / 1e3; | ||
if ($handle_serialize) { | ||
return serialize($value); | ||
} else { | ||
return $value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
namespace phpcassa\Schema\DataType; | ||
|
||
/** | ||
* Stores data as an 4-byte signed integer. | ||
* | ||
* @package phpcassa\Schema\DataType | ||
*/ | ||
class Int32Type extends CassandraType { | ||
|
||
public function pack($value, $is_name=null, $slice_end=null, $is_data=null) | ||
{ | ||
// signed/unsigned doesn't matter when packing | ||
return pack('N', $value); | ||
} | ||
|
||
public function unpack($data, $is_name=null) | ||
{ | ||
return current(unpack('l', strrev($data))); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.