-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathexample.php
More file actions
24 lines (18 loc) · 729 Bytes
/
example.php
File metadata and controls
24 lines (18 loc) · 729 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
<?php
include("src/CBOR/CBOREncoder.php");
include("src/CBOR/CBORExceptions.php");
include("src/CBOR/Types/CBORByteString.php");
//target for encode
$target = array(true, array("variable1" => 100000, "variable2" => "Hello, World!", "Hello!"), 0.234, 0, null, 590834290589032580);
//encoded string
$encoded_data = \CBOR\CBOREncoder::encode($target);
//debug info output
$byte_arr = unpack("C*", $encoded_data);
echo "Byte hex map = " . implode(" ", array_map(function($byte){
return "0x" . strtoupper(dechex($byte));
}, $byte_arr)) . PHP_EOL;
echo "Byte dec map = " . implode(" ", $byte_arr) . PHP_EOL;
//decode
$decoded_variable = \CBOR\CBOREncoder::decode($encoded_data);
//output
var_dump($decoded_variable);