Overview

Namespaces

  • cassandra
  • None
  • PHP
  • phpcassa
    • Batch
    • Connection
    • Index
    • Iterator
    • Schema
      • DataType
    • Util
    • UUID

Classes

  • AsciiType
  • BooleanType
  • BytesType
  • CassandraType
  • CompositeType
  • DateType
  • DoubleType
  • FloatType
  • Int32Type
  • IntegerType
  • LexicalUUIDType
  • LongType
  • TimeUUIDType
  • UTF8Type
  • UUIDType

Interfaces

  • Serialized
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: namespace phpcassa\Schema\DataType;
 3: 
 4: /**
 5:  * Stores data in a variable-length BigInteger-compatible format.
 6:  *
 7:  * This is the most space-efficient integer format.
 8:  *
 9:  * @package phpcassa\Schema\DataType
10:  */
11: class IntegerType extends CassandraType {
12: 
13:     public function pack($value, $is_name=null, $slice_end=null, $is_data=null)
14:     {
15:         $value = (int)$value;
16:         $out = array();
17:         if ($value >= 0) {
18:             while ($value >= 256) {
19:                 $out[] = pack('C', 0xff & $value);
20:                 $value >>= 8;
21:             }
22:             $out[] = pack('C', 0xff & $value);
23:             if ($value > 127) {
24:                 $out[] = chr('00');
25:             }
26:         } else {
27:             $value = -1 - $value;
28:             while ($value >= 256) {
29:                 $out[] = pack('C', 0xff & ~$value);
30:                 $value >>= 8;
31:             }
32:             if ($value <= 127) {
33:                 $out[] = pack('C', 0xff & ~$value);
34:             } else {
35:                 $top = pack('n', 0xffff & ~$value);
36:                 // we have two bytes, need to reverse them
37:                 $out[] = strrev($top);
38:             }
39:         }
40: 
41:         return strrev(implode($out));
42:     }
43: 
44:     public function unpack($data, $is_name=null)
45:     {
46:         $val = hexdec(bin2hex($data));
47:         if ((ord($data[0]) & 128) != 0)
48:             $val = $val - (1 << (strlen($data) * 8));
49:         return $val;
50:     }
51: }
52: 
53: 
phpcassa API documentation generated by ApiGen 2.8.0