forked from nikkiii/gsquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.php
More file actions
67 lines (56 loc) · 1.13 KB
/
Copy pathbuffer.php
File metadata and controls
67 lines (56 loc) · 1.13 KB
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
<?php
/**
* A simple buffer for reading standard data types in PHP
*
* @author Nikki
*
*/
class Buffer {
/**
* The data object (String in this case)
*/
private $data;
public function __construct($data) {
$this->data = $data;
}
public function getByte() {
$byte = substr($this->data, 0, 1);
$this->skip(1);
return ord($byte);
}
public function getChar() {
return sprintf("%c", $this->getByte());
}
public function getShort() {
$lo = $this->getByte();
$hi = $this->getByte();
$short = ($hi << 8) | $lo;
return $short;
}
public function getInteger() {
$lo = $this->getShort();
$hi = $this->getShort();
$long = ($hi << 16) | $lo;
return $long;
}
public function getFloat() {
$f = @unpack("f1float", $this->data);
$this->skip(4);
return $f['float'];
}
public function getString() {
$end = strpos($this->data, "\0");
$str = substr($this->data, 0, $end);
$this->skip($end + 1);
return $str;
}
public function skip($size) {
$this->data = substr($this->data, $size);
}
public function getData() {
return $this->data;
}
public function close() {
unset($this->data);
}
}