1 | <?php |
||
8 | class Buffer implements BufferInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var int |
||
12 | */ |
||
13 | protected $size; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $buffer; |
||
19 | |||
20 | /** |
||
21 | * @var MathAdapterInterface |
||
22 | */ |
||
23 | protected $math; |
||
24 | |||
25 | /** |
||
26 | * @param string $byteString |
||
27 | * @param null|integer $byteSize |
||
28 | * @param MathAdapterInterface $math |
||
29 | * @throws \Exception |
||
30 | */ |
||
31 | public function __construct($byteString = '', $byteSize = null, MathAdapterInterface $math = null) |
||
46 | |||
47 | /** |
||
48 | * Create a new buffer from a hex string |
||
49 | * |
||
50 | * @param string $hexString |
||
51 | * @param integer $byteSize |
||
52 | * @param MathAdapterInterface $math |
||
53 | * @return Buffer |
||
54 | * @throws \Exception |
||
55 | */ |
||
56 | public static function hex($hexString = '', $byteSize = null, MathAdapterInterface $math = null) |
||
66 | |||
67 | /** |
||
68 | * @param int|string $integer |
||
69 | * @param null|int $byteSize |
||
70 | * @param MathAdapterInterface|null $math |
||
71 | * @return Buffer |
||
72 | */ |
||
73 | public static function int($integer, $byteSize = null, MathAdapterInterface $math = null) |
||
74 | { |
||
75 | $math = $math ?: EccFactory::getAdapter(); |
||
76 | $binary = pack("H*", $math->decHex($integer)); |
||
77 | return new self($binary, $byteSize, $math); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param integer $start |
||
82 | * @param integer|null $end |
||
83 | * @return Buffer |
||
84 | * @throws \Exception |
||
85 | */ |
||
86 | public function slice($start, $end = null) |
||
104 | |||
105 | /** |
||
106 | * Get the size of the buffer to be returned |
||
107 | * |
||
108 | * @return int |
||
109 | */ |
||
110 | public function getSize() |
||
114 | |||
115 | /** |
||
116 | * Get the size of the value stored in the buffer |
||
117 | * |
||
118 | * @return int |
||
119 | */ |
||
120 | public function getInternalSize() |
||
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | public function getBinary() |
||
141 | |||
142 | /** |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getHex() |
||
149 | |||
150 | /** |
||
151 | * @return int|string |
||
152 | */ |
||
153 | public function getInt() |
||
157 | |||
158 | /** |
||
159 | * @return Buffer |
||
160 | */ |
||
161 | public function flip() |
||
165 | |||
166 | /** |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function equals(BufferInterface $other) |
||
174 | } |
||
175 |