Repository navigation
Expand file tree
/
Copy pathMessage.php
More file actions
82 lines (67 loc) · 1.76 KB
/
Copy pathMessage.php
File metadata and controls
82 lines (67 loc) · 1.76 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
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Nsq;
class Message
{
/**
* @var string nanosecond
*/
protected string $timestamp;
protected int $attempts;
protected string $messageId;
protected string $body;
public function __construct(string $payload)
{
// u16int to u32int
$left = sprintf('%u', Packer::unpackUInt32(substr($payload, 0, 4))[1]);
$right = sprintf('%u', Packer::unpackUInt32(substr($payload, 4, 4))[1]);
$this->timestamp = bcadd(bcmul($left, '4294967296'), $right);
$this->attempts = Packer::unpackUInt16(substr($payload, 8, 2));
$this->messageId = Packer::unpackString(substr($payload, 10, 16));
$this->body = Packer::unpackString(substr($payload, 26));
}
public function getTimestamp()
{
return $this->timestamp;
}
public function setTimestamp($timestamp)
{
$this->timestamp = $timestamp;
return $this;
}
public function getAttempts()
{
return $this->attempts;
}
public function setAttempts($attempts)
{
$this->attempts = $attempts;
return $this;
}
public function getMessageId(): string
{
return $this->messageId;
}
public function setMessageId(string $messageId): Message
{
$this->messageId = $messageId;
return $this;
}
public function getBody(): string
{
return $this->body;
}
public function setBody(string $body): Message
{
$this->body = $body;
return $this;
}
}