-
Notifications
You must be signed in to change notification settings - Fork 0
/
OMapCompareTask.php
80 lines (72 loc) · 1.97 KB
/
OMapCompareTask.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
78
79
80
<?php
namespace Aternos\Rados\Operation\Common\Task;
use Aternos\Rados\Constants\OMapComparisonOperator;
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 an omap value satisfies a comparison,
* with the supplied value on the right hand side (i.e.
* for OP_LT, the comparison is actual_value < value)
* For reasons unknown to me, this is the opposite of how xattr comparison works.
*
* @extends CommonOperationTask<null>
*/
class OMapCompareTask extends CommonOperationTask
{
protected ?CData $result = null;
/**
* @param string $key
* @param string $value
* @param OMapComparisonOperator $operator
*/
public function __construct(
protected string $key,
protected string $value,
protected OMapComparisonOperator $operator = OMapComparisonOperator::Equal
)
{
}
/**
* @inheritDoc
* @throws RadosException
*/
protected function parseResult(): null
{
RadosObjectException::handle($this->result?->cdata ?? 0);
return null;
}
/**
* @inheritDoc
*/
protected function initTask(Operation $operation): void
{
$this->result = $operation->getFFI()->new('int');
$operation->getFFI()->{$this->getFunctionName($operation)}(
$operation->getCData(),
$this->key,
$this->operator->getCValue($operation->getFFI()),
$this->value,
strlen($this->key),
strlen($this->value),
FFI::addr($this->result)
);
}
/**
* @inheritDoc
*/
protected function getReadFunctionName(): string
{
return "rados_read_op_omap_cmp2";
}
/**
* @inheritDoc
*/
protected function getWriteFunctionName(): string
{
return "rados_write_op_omap_cmp2";
}
}