酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

70 lines
1.2 KiB

  1. <?php
  2. namespace PhpZip\Util;
  3. /**
  4. * Pack util.
  5. *
  6. * @author Ne-Lexa alexey@nelexa.ru
  7. * @license MIT
  8. *
  9. * @internal
  10. */
  11. final class PackUtil
  12. {
  13. /**
  14. * @param int $longValue
  15. *
  16. * @return string
  17. */
  18. public static function packLongLE($longValue)
  19. {
  20. if (\PHP_VERSION_ID >= 506030) {
  21. return pack('P', $longValue);
  22. }
  23. $left = 0xffffffff00000000;
  24. $right = 0x00000000ffffffff;
  25. $r = ($longValue & $left) >> 32;
  26. $l = $longValue & $right;
  27. return pack('VV', $l, $r);
  28. }
  29. /**
  30. * @param string $value
  31. *
  32. * @return int
  33. */
  34. public static function unpackLongLE($value)
  35. {
  36. if (\PHP_VERSION_ID >= 506030) {
  37. return unpack('P', $value)[1];
  38. }
  39. $unpack = unpack('Va/Vb', $value);
  40. return $unpack['a'] + ($unpack['b'] << 32);
  41. }
  42. /**
  43. * Cast to signed int 32-bit.
  44. *
  45. * @param int $int
  46. *
  47. * @return int
  48. */
  49. public static function toSignedInt32($int)
  50. {
  51. if (\PHP_INT_SIZE === 8) {
  52. $int &= 0xffffffff;
  53. if ($int & 0x80000000) {
  54. return $int - 0x100000000;
  55. }
  56. }
  57. return $int;
  58. }
  59. }