1 | <?php |
||
7 | class TemplateFactory |
||
8 | { |
||
9 | /** |
||
10 | * @var \BitWasp\Buffertools\Template |
||
11 | */ |
||
12 | private $template; |
||
13 | |||
14 | /** |
||
15 | * @var TypeFactoryInterface |
||
16 | */ |
||
17 | private $types; |
||
18 | |||
19 | /** |
||
20 | * TemplateFactory constructor. |
||
21 | * @param Template|null $template |
||
22 | * @param TypeFactoryInterface|null $typeFactory |
||
23 | */ |
||
24 | 54 | public function __construct(Template $template = null, TypeFactoryInterface $typeFactory = null) |
|
29 | |||
30 | /** |
||
31 | * Return the Template as it stands. |
||
32 | * |
||
33 | * @return Template |
||
34 | */ |
||
35 | 54 | public function getTemplate() |
|
39 | |||
40 | /** |
||
41 | * Add a Uint8 serializer to the template |
||
42 | * |
||
43 | * @return TemplateFactory |
||
44 | */ |
||
45 | 2 | public function uint8() |
|
50 | |||
51 | /** |
||
52 | * Add a little-endian Uint8 serializer to the template |
||
53 | * |
||
54 | * @return TemplateFactory |
||
55 | */ |
||
56 | 2 | public function uint8le(): TemplateFactory |
|
61 | |||
62 | /** |
||
63 | * Add a Uint16 serializer to the template |
||
64 | * |
||
65 | * @return TemplateFactory |
||
66 | */ |
||
67 | 2 | public function uint16(): TemplateFactory |
|
72 | |||
73 | /** |
||
74 | * Add a little-endian Uint16 serializer to the template |
||
75 | * |
||
76 | * @return TemplateFactory |
||
77 | */ |
||
78 | 2 | public function uint16le(): TemplateFactory |
|
83 | |||
84 | /** |
||
85 | * Add a Uint32 serializer to the template |
||
86 | * |
||
87 | * @return TemplateFactory |
||
88 | */ |
||
89 | 2 | public function uint32(): TemplateFactory |
|
94 | |||
95 | /** |
||
96 | * Add a little-endian Uint32 serializer to the template |
||
97 | * |
||
98 | * @return TemplateFactory |
||
99 | */ |
||
100 | 2 | public function uint32le(): TemplateFactory |
|
105 | |||
106 | /** |
||
107 | * Add a Uint64 serializer to the template |
||
108 | * |
||
109 | * @return TemplateFactory |
||
110 | */ |
||
111 | 2 | public function uint64(): TemplateFactory |
|
116 | |||
117 | /** |
||
118 | * Add a little-endian Uint64 serializer to the template |
||
119 | * |
||
120 | * @return TemplateFactory |
||
121 | */ |
||
122 | 2 | public function uint64le(): TemplateFactory |
|
127 | |||
128 | /** |
||
129 | * Add a Uint128 serializer to the template |
||
130 | * |
||
131 | * @return TemplateFactory |
||
132 | */ |
||
133 | 2 | public function uint128(): TemplateFactory |
|
138 | |||
139 | /** |
||
140 | * Add a little-endian Uint128 serializer to the template |
||
141 | * |
||
142 | * @return TemplateFactory |
||
143 | */ |
||
144 | 2 | public function uint128le(): TemplateFactory |
|
149 | |||
150 | /** |
||
151 | * Add a Uint256 serializer to the template |
||
152 | * |
||
153 | * @return TemplateFactory |
||
154 | */ |
||
155 | 2 | public function uint256(): TemplateFactory |
|
160 | |||
161 | /** |
||
162 | * Add a little-endian Uint256 serializer to the template |
||
163 | * |
||
164 | * @return TemplateFactory |
||
165 | */ |
||
166 | 2 | public function uint256le(): TemplateFactory |
|
171 | |||
172 | /** |
||
173 | * Add a int8 serializer to the template |
||
174 | * |
||
175 | * @return TemplateFactory |
||
176 | */ |
||
177 | 2 | public function int8(): TemplateFactory |
|
182 | |||
183 | /** |
||
184 | * Add a little-endian Int8 serializer to the template |
||
185 | * |
||
186 | * @return TemplateFactory |
||
187 | */ |
||
188 | 2 | public function int8le(): TemplateFactory |
|
193 | |||
194 | /** |
||
195 | * Add a int16 serializer to the template |
||
196 | * |
||
197 | * @return TemplateFactory |
||
198 | */ |
||
199 | 2 | public function int16(): TemplateFactory |
|
204 | |||
205 | /** |
||
206 | * Add a little-endian Int16 serializer to the template |
||
207 | * |
||
208 | * @return TemplateFactory |
||
209 | */ |
||
210 | 2 | public function int16le(): TemplateFactory |
|
215 | |||
216 | /** |
||
217 | * Add a int32 serializer to the template |
||
218 | * |
||
219 | * @return TemplateFactory |
||
220 | */ |
||
221 | 2 | public function int32(): TemplateFactory |
|
226 | |||
227 | /** |
||
228 | * Add a little-endian Int serializer to the template |
||
229 | * |
||
230 | * @return TemplateFactory |
||
231 | */ |
||
232 | 2 | public function int32le(): TemplateFactory |
|
237 | |||
238 | /** |
||
239 | * Add a int64 serializer to the template |
||
240 | * |
||
241 | * @return TemplateFactory |
||
242 | */ |
||
243 | 2 | public function int64(): TemplateFactory |
|
248 | |||
249 | /** |
||
250 | * Add a little-endian Int64 serializer to the template |
||
251 | * |
||
252 | * @return TemplateFactory |
||
253 | */ |
||
254 | 2 | public function int64le(): TemplateFactory |
|
259 | |||
260 | /** |
||
261 | * Add a int128 serializer to the template |
||
262 | * |
||
263 | * @return TemplateFactory |
||
264 | */ |
||
265 | 2 | public function int128(): TemplateFactory |
|
270 | |||
271 | /** |
||
272 | * Add a little-endian Int128 serializer to the template |
||
273 | * |
||
274 | * @return TemplateFactory |
||
275 | */ |
||
276 | 2 | public function int128le(): TemplateFactory |
|
281 | |||
282 | /** |
||
283 | * Add a int256 serializer to the template |
||
284 | * |
||
285 | * @return TemplateFactory |
||
286 | */ |
||
287 | 2 | public function int256(): TemplateFactory |
|
292 | |||
293 | /** |
||
294 | * Add a little-endian Int256 serializer to the template |
||
295 | * |
||
296 | * @return TemplateFactory |
||
297 | */ |
||
298 | 2 | public function int256le(): TemplateFactory |
|
303 | |||
304 | /** |
||
305 | * Add a VarInt serializer to the template |
||
306 | * |
||
307 | * @return TemplateFactory |
||
308 | */ |
||
309 | 2 | public function varint(): TemplateFactory |
|
314 | |||
315 | /** |
||
316 | * Add a VarString serializer to the template |
||
317 | * |
||
318 | * @return TemplateFactory |
||
319 | */ |
||
320 | 2 | public function varstring(): TemplateFactory |
|
325 | |||
326 | /** |
||
327 | * Add a byte string serializer to the template. This serializer requires a length to |
||
328 | * pad/truncate to. |
||
329 | * |
||
330 | * @param int $length |
||
331 | * @return TemplateFactory |
||
332 | */ |
||
333 | public function bytestring(int $length): TemplateFactory |
||
338 | |||
339 | /** |
||
340 | * Add a little-endian byte string serializer to the template. This serializer requires |
||
341 | * a length to pad/truncate to. |
||
342 | * |
||
343 | * @param int $length |
||
344 | * @return TemplateFactory |
||
345 | */ |
||
346 | public function bytestringle(int $length): TemplateFactory |
||
351 | |||
352 | /** |
||
353 | * Add a vector serializer to the template. A $readHandler must be provided if the |
||
354 | * template will be used to deserialize a vector, since it's contents are not known. |
||
355 | * |
||
356 | * The $readHandler should operate on the parser reference, reading the bytes for each |
||
357 | * item in the collection. |
||
358 | * |
||
359 | * @param callable $readHandler |
||
360 | * @return TemplateFactory |
||
361 | */ |
||
362 | 2 | public function vector(callable $readHandler): TemplateFactory |
|
367 | } |
||
368 |