-
Notifications
You must be signed in to change notification settings - Fork 3
/
rlp.html
426 lines (355 loc) · 18.8 KB
/
rlp.html
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
---
layout: page
title: RLP
icon: fa-random
order: 8
---
<section class="row-fluid">
<div class="">
<div class="row-fluid">
<div class="span8 content class">
<h1>RLP</h1>
<p><em>It's a instance for ethereum recursive length encoding.</em></p>
<p>RLP encode:</p>
<pre><code class="language-php">use Web3p\RLP\RLP;
$rlp = new RLP;
// c483646f67
$encoded = $rlp->encode(['dog']);
// 83646f67
$encoded = $rlp->encode('dog');</code></pre>
<p>RLP decode:</p>
<pre><code class="language-php">use Web3p\RLP\RLP;
use Web3p\RLP\Types\Str;
$rlp = new RLP;
$encoded = $rlp->encode(['dog']);
// only accept 0x prefixed hex string
$decoded = $rlp->decode('0x' . $encoded);
// show 646f67
echo $decoded[0];
// show dog
echo hex2bin($decoded[0]);
// or you can
echo Str::decodeHex($decoded[0]);</code></pre>
<section id="summary">
<h2>Summary</h2>
<section class="row-fluid heading">
<section class="span4">
<a href="#methods">Methods</a>
</section>
<section class="span4">
<a href="#properties">Properties</a>
</section>
<section class="span4">
<a href="#constants">Constants</a>
</section>
</section>
<section class="row-fluid public">
<section class="span4">
<a href="/rlp.html#method_encode" class="">encode()</a><br />
<a href="/rlp.html#method_decode" class="">decode()</a><br />
</section>
<section class="span4">
<em>No public properties found</em>
</section>
<section class="span4">
<em>No constants found</em>
</section>
</section>
<section class="row-fluid protected">
<section class="span4">
<a href="/rlp.html#method_decodeData" class="">decodeData()</a><br />
<a href="/rlp.html#method_encodeLength" class="">encodeLength()</a><br />
<a href="/rlp.html#method_intToHex" class="">intToHex()</a><br />
<a href="/rlp.html#method_padToEven" class="">padToEven()</a><br />
<a href="/rlp.html#method_encodeInput" class="">encodeInput()</a><br />
</section>
<section class="span4">
<em>No protected properties found</em>
</section>
<section class="span4">
<em>N/A</em>
</section>
</section>
<section class="row-fluid private">
<section class="span4">
<em>No private methods found</em>
</section>
<section class="span4">
<em>No private properties found</em>
</section>
<section class="span4">
<em>N/A</em>
</section>
</section>
</section>
</div>
<aside class="span4 detailsbar">
<dl>
<dt>File</dt>
<dd><a href="rlp.html"><div class="path-wrapper">RLP.php</div></a></dd>
<dt>Package</dt>
<dd><div class="namespace-wrapper">Default</div></dd>
<dt>Class hierarchy</dt>
<dd class="hierarchy">
<div class="namespace-wrapper">\Web3p\RLP\RLP</div>
</dd>
<dt>See also</dt>
<dd><a href="https://www.web3p.xyz"><span class="namespace-wrapper">https://www.web3p.xyz</span></a></dd>
</dl>
<h2>Tags</h2>
<table class="table table-condensed">
<tr>
<th>
author
</th>
<td>
<p>Peter Lai <a href="mailto:alk03073135@gmail.com">alk03073135@gmail.com</a></p>
</td>
</tr>
<tr>
<th>
filesource
</th>
<td>
<p><a href="https://github.com/web3p/rlp">https://github.com/web3p/rlp</a></p>
</td>
</tr>
</table>
</aside>
</div>
<a id="methods" name="methods"></a>
<div class="row-fluid">
<div class="span8 content class"><h2>Methods</h2></div>
<aside class="span4 detailsbar"></aside>
</div>
<div class="row-fluid">
<div class="span8 content class">
<a id="method_encode" name="method_encode" class="anchor"></a>
<article class="method">
<h3 class="public ">encode()</h3>
<pre class="signature" style="margin-right: 54px;">encode(array <span class="argument">$inputs</span>) : string</pre>
<p><em>Return RLP encoded of the given inputs.</em></p>
<h4>Parameters</h4>
<table class="table table-condensed table-hover">
<tr>
<td>array</td>
<td>$inputs </td>
<td><p>array of data you want to RLP encode</p></td>
</tr>
</table>
<h4>Returns</h4>
string
— <p>RLP encoded hex string of inputs</p>
</article>
</div>
<aside class="span4 detailsbar">
<h1><i class="icon-arrow-down"></i></h1>
<dl>
<dt>Inherited from</dt>
<dd><a href="/rlp.html"><div class="path-wrapper">\Web3p\RLP\RLP</div></a></dd>
</dl>
<h2>Tags</h2>
<table class="table table-condensed">
<tr><td colspan="2"><em>None found</em></td></tr>
</table>
</aside>
</div>
<div class="row-fluid">
<div class="span8 content class">
<a id="method_decode" name="method_decode" class="anchor"></a>
<article class="method">
<h3 class="public ">decode()</h3>
<pre class="signature" style="margin-right: 54px;">decode(string <span class="argument">$input</span>) : array</pre>
<p><em>Return RLP decoded of the given hex encoded data.</em></p>
<h4>Parameters</h4>
<table class="table table-condensed table-hover">
<tr>
<td>string</td>
<td>$input </td>
<td><p>hex encoded data</p></td>
</tr>
</table>
<h4>Returns</h4>
array
— <p>decoded data</p>
</article>
</div>
<aside class="span4 detailsbar">
<h1><i class="icon-arrow-down"></i></h1>
<dl>
<dt>Inherited from</dt>
<dd><a href="/rlp.html"><div class="path-wrapper">\Web3p\RLP\RLP</div></a></dd>
</dl>
<h2>Tags</h2>
<table class="table table-condensed">
<tr><td colspan="2"><em>None found</em></td></tr>
</table>
</aside>
</div>
<div class="row-fluid">
<div class="span8 content class">
<a id="method_decodeData" name="method_decodeData" class="anchor"></a>
<article class="method">
<h3 class="protected ">decodeData()</h3>
<pre class="signature" style="margin-right: 54px;">decodeData(string <span class="argument">$input</span>) : array</pre>
<p><em>Main function of RLP decode.</em></p>
<h4>Parameters</h4>
<table class="table table-condensed table-hover">
<tr>
<td>string</td>
<td>$input </td>
<td><p>hex encoded data</p></td>
</tr>
</table>
<h4>Returns</h4>
array
— <p>decoded data</p>
</article>
</div>
<aside class="span4 detailsbar">
<h1><i class="icon-arrow-down"></i></h1>
<dl>
<dt>Inherited from</dt>
<dd><a href="/rlp.html"><div class="path-wrapper">\Web3p\RLP\RLP</div></a></dd>
</dl>
<h2>Tags</h2>
<table class="table table-condensed">
<tr><td colspan="2"><em>None found</em></td></tr>
</table>
</aside>
</div>
<div class="row-fluid">
<div class="span8 content class">
<a id="method_encodeLength" name="method_encodeLength" class="anchor"></a>
<article class="method">
<h3 class="protected ">encodeLength()</h3>
<pre class="signature" style="margin-right: 54px;">encodeLength(integer <span class="argument">$length</span>, integer <span class="argument">$offset</span>) : string</pre>
<p><em>Return RLP encoded the length of data.</em></p>
<h4>Parameters</h4>
<table class="table table-condensed table-hover">
<tr>
<td>integer</td>
<td>$length </td>
<td><p>length of data</p></td>
</tr>
<tr>
<td>integer</td>
<td>$offset </td>
<td><p>offset of data</p></td>
</tr>
</table>
<h4>Returns</h4>
string
— <p>hex encoded of the length</p>
</article>
</div>
<aside class="span4 detailsbar">
<h1><i class="icon-arrow-down"></i></h1>
<dl>
<dt>Inherited from</dt>
<dd><a href="/rlp.html"><div class="path-wrapper">\Web3p\RLP\RLP</div></a></dd>
</dl>
<h2>Tags</h2>
<table class="table table-condensed">
<tr><td colspan="2"><em>None found</em></td></tr>
</table>
</aside>
</div>
<div class="row-fluid">
<div class="span8 content class">
<a id="method_intToHex" name="method_intToHex" class="anchor"></a>
<article class="method">
<h3 class="protected ">intToHex()</h3>
<pre class="signature" style="margin-right: 54px;">intToHex(integer <span class="argument">$input</span>) : string</pre>
<p><em>Return hex of the given integer.</em></p>
<h4>Parameters</h4>
<table class="table table-condensed table-hover">
<tr>
<td>integer</td>
<td>$input </td>
<td><p>integer</p></td>
</tr>
</table>
<h4>Returns</h4>
string
— <p>hex encoded of the input</p>
</article>
</div>
<aside class="span4 detailsbar">
<h1><i class="icon-arrow-down"></i></h1>
<dl>
<dt>Inherited from</dt>
<dd><a href="/rlp.html"><div class="path-wrapper">\Web3p\RLP\RLP</div></a></dd>
</dl>
<h2>Tags</h2>
<table class="table table-condensed">
<tr><td colspan="2"><em>None found</em></td></tr>
</table>
</aside>
</div>
<div class="row-fluid">
<div class="span8 content class">
<a id="method_padToEven" name="method_padToEven" class="anchor"></a>
<article class="method">
<h3 class="protected ">padToEven()</h3>
<pre class="signature" style="margin-right: 54px;">padToEven(string <span class="argument">$input</span>) : string</pre>
<p><em>Pad hex encoded data to even length (add 0).</em></p>
<h4>Parameters</h4>
<table class="table table-condensed table-hover">
<tr>
<td>string</td>
<td>$input </td>
<td><p>hex encoded string</p></td>
</tr>
</table>
<h4>Returns</h4>
string
— <p>hex encoded string</p>
</article>
</div>
<aside class="span4 detailsbar">
<h1><i class="icon-arrow-down"></i></h1>
<dl>
<dt>Inherited from</dt>
<dd><a href="/rlp.html"><div class="path-wrapper">\Web3p\RLP\RLP</div></a></dd>
</dl>
<h2>Tags</h2>
<table class="table table-condensed">
<tr><td colspan="2"><em>None found</em></td></tr>
</table>
</aside>
</div>
<div class="row-fluid">
<div class="span8 content class">
<a id="method_encodeInput" name="method_encodeInput" class="anchor"></a>
<article class="method">
<h3 class="protected ">encodeInput()</h3>
<pre class="signature" style="margin-right: 54px;">encodeInput(mixed <span class="argument">$input</span>) : string</pre>
<p><em>Main encode function to transform data to hex encoded string.</em></p>
<h4>Parameters</h4>
<table class="table table-condensed table-hover">
<tr>
<td>mixed</td>
<td>$input </td>
<td><p>data</p></td>
</tr>
</table>
<h4>Returns</h4>
string
— <p>hex encoded string</p>
</article>
</div>
<aside class="span4 detailsbar">
<h1><i class="icon-arrow-down"></i></h1>
<dl>
<dt>Inherited from</dt>
<dd><a href="/rlp.html"><div class="path-wrapper">\Web3p\RLP\RLP</div></a></dd>
</dl>
<h2>Tags</h2>
<table class="table table-condensed">
<tr><td colspan="2"><em>None found</em></td></tr>
</table>
</aside>
</div>
</div>
</section>