File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 24
24
class Util {
25
25
private static $ little_endian = null ;
26
26
27
+ /**
28
+ * Reads data
29
+ *
30
+ * @param string $type type for unpack()
31
+ * @param string $data Data to process
32
+ *
33
+ * @return mixed
34
+ */
27
35
public static function loadData ($ type , $ data ) {
28
36
if (!$ data ) {
29
37
return $ data ;
@@ -32,6 +40,13 @@ public static function loadData($type, $data) {
32
40
return current ($ tmp );
33
41
}
34
42
43
+ /**
44
+ * Changes endianity
45
+ *
46
+ * @param string $value Binary value
47
+ *
48
+ * @return string
49
+ */
35
50
public static function swap($ binValue ) {
36
51
$ result = $ binValue {strlen ($ binValue ) - 1 };
37
52
for ($ i = strlen ($ binValue ) - 2 ; $ i >= 0 ; $ i --) {
@@ -41,6 +56,13 @@ public static function swap($binValue) {
41
56
return $ result ;
42
57
}
43
58
59
+ /**
60
+ * Encodes double value to correct endianity
61
+ *
62
+ * @param double $value Value to pack
63
+ *
64
+ * @return string
65
+ */
44
66
public static function packDouble ($ value ) {
45
67
$ bin = pack ("d " , (double ) $ value );
46
68
You can’t perform that action at this time.
0 commit comments