-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeserializer.php
More file actions
84 lines (78 loc) · 2.03 KB
/
Copy pathDeserializer.php
File metadata and controls
84 lines (78 loc) · 2.03 KB
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
<?php
/**
* efxphp (http://emilmalinov.com/efxphp)
*
* @copyright Copyright (c) 2015 Emil Malinov
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link http://github.com/emilkm/efxphp
* @package efxphp
*/
namespace emilkm\efxphp\Amf;
/**
* @author Emil Malinov
* @package efxphp
* @subpackage amf
*/
class Deserializer
{
protected $in;
/**
* @param AbstractInput $input
*/
public function __construct(AbstractInput $input)
{
$this->in = $input;
}
/**
* @param mixed $data
*
* @return ActionMessage
*/
public function readMessage(&$data)
{
$this->in->setData($data);
$version = $this->in->readShort();
$message = new ActionMessage($version);
// Read headers
$headerCount = $this->in->readShort();
for ($i = 0; $i < $headerCount; ++$i) {
$message->headers[] = $this->readHeader();
}
// Read bodies
$bodyCount = $this->in->readShort();
for ($i = 0; $i < $bodyCount; ++$i) {
$message->bodies[] = $this->readBody();
}
return $message;
}
/**
* Deserialize a message header
*
* @return MessageHeader
*/
protected function readHeader()
{
$this->in->resetReferences();
$header = new MessageHeader();
$header->name = $this->in->readUtf();
$header->mustUnderstand = $this->in->readBoolean();
$this->in->skipBytes(4); // skip header length
$header->data = $this->in->readObject();
return $header;
}
/**
* Deserialize a message body
*
* @return MessageBody
*/
protected function readBody()
{
$this->in->resetReferences();
$message = new MessageBody();
$message->targetURI = $this->in->readUtf();
$message->responseURI = $this->in->readUtf();
$this->in->skipBytes(4); // skip message length
$message->data = $this->in->readObject();
return $message;
}
}