-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompareExtTask.php
77 lines (69 loc) · 1.84 KB
/
CompareExtTask.php
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
<?php
namespace Aternos\Rados\Operation\Common\Task;
use Aternos\Rados\Constants\Constants;
use Aternos\Rados\Exception\RadosException;
use Aternos\Rados\Exception\RadosObjectException;
use Aternos\Rados\Operation\Common\CommonOperationTask;
use Aternos\Rados\Operation\Operation;
use FFI;
use FFI\CData;
/**
* Ensure that given object range (extent) satisfies comparison.
*
* @extends CommonOperationTask<true|int>
*/
class CompareExtTask extends CommonOperationTask
{
protected ?CData $result = null;
/**
* @param string $buffer - buffer containing bytes to be compared with object contents
* @param int $offset - object byte offset at which to start the comparison
*/
public function __construct(
protected string $buffer,
protected int $offset
)
{
}
/**
* @inheritDoc
* @throws RadosException
* @return true|int - true on match, offset of mismatch on failure
*/
protected function parseResult(): int
{
$result = RadosObjectException::handle($this->result?->cdata ?? 0);
if ($result === 0) {
return true;
}
return -$result - Constants::MAX_ERRNO;
}
/**
* @inheritDoc
*/
protected function initTask(Operation $operation): void
{
$this->result = $operation->getFFI()->new('int');
$operation->getFFI()->{$this->getFunctionName($operation)}(
$operation->getCData(),
$this->buffer,
strlen($this->buffer),
$this->offset,
FFI::addr($this->result)
);
}
/**
* @inheritDoc
*/
protected function getReadFunctionName(): string
{
return "rados_read_op_cmpext";
}
/**
* @inheritDoc
*/
protected function getWriteFunctionName(): string
{
return "rados_write_op_cmpext";
}
}