-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·40 lines (29 loc) · 906 Bytes
/
index.php
File metadata and controls
executable file
·40 lines (29 loc) · 906 Bytes
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
<?php
require __DIR__.'/vendor/autoload.php';
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use CBOR\CBOREncoder;
$app = AppFactory::create();
$app->get('/', function (Request $request, Response $response, $args) {
$target = [
[2 => ['c' => true]],
[3 => ['p' => 10]],
1,
'string',
[1, 2, 3, 4],
];
//encoded string
$encoded_data = CBOREncoder::encode($target);
$byte_arr = unpack('C*', $encoded_data);
$dechex = implode(' ', array_map(function ($byte) {
$dechex = dechex($byte);
if (strlen($dechex) == 1 || (is_numeric($dechex) && $dechex < 10)) {
$dechex = '0'.$dechex;
}
return '0x'.$dechex;
}, $byte_arr));
$response->getBody()->write($dechex);
return $response;
});
$app->run();