-
Notifications
You must be signed in to change notification settings - Fork 1
/
WS.php
78 lines (59 loc) · 1.16 KB
/
WS.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace GDO\Util;
use GDO\Core\Application;
/**
* Websocket i/o utility
*
* @version 7.0.3
*/
final class WS
{
public static function wrFloat(?float $float): string
{
if ($float === null)
{
$float = NAN;
}
return pack('f', floatval($float));
}
public static function wrDouble(?float $double): string
{
if ($double === null)
{
$double = NAN;
}
return pack('d', doubleval($double));
}
public static function wr8(int $value): string
{
return self::wrN(1, $value);
}
public static function wr16(int $value): string
{
return self::wrN(2, $value);
}
public static function wr32(int $value): string
{
return self::wrN(4, $value);
}
public static function wr64(int $value): string
{
return self::wrN(8, $value);
}
public static function wrString(string $string): string
{
return urlencode($string) . "\0";
}
public static function wrN(int $bytes, int $value): string
{
$value = (int)$value;
$write = '';
for ($i = 0; $i < $bytes; $i++)
{
$write = chr($value & 0xFF) . $write;
$value >>= 8;
}
return $write;
}
}