private function readDecimal()

in src/Apache/Ignite/Internal/Binary/BinaryCommunicator.php [279:303]


    private function readDecimal(MessageBuffer $buffer): BigDecimal
    {
        $scale = $buffer->readInteger();
        $value = $buffer->readString(false);
        $isNegative = (ord($value[0]) & 0x80) !== 0;
        if ($isNegative) {
            $value[0] = chr(ord($value[0]) & 0x7F);
        }
        $hexValue = '';
        for ($i = 0; $i < strlen($value); $i++) {
            $hex = dechex(ord($value[$i]));
            if (strlen($hex) < 2) {
                $hex = str_repeat('0', 2 - strlen($hex)) . $hex;
            }
            $hexValue .= $hex;
        }
        $result = BigDecimal::ofUnscaledValue(BigInteger::parse($hexValue, 16), $scale >= 0 ? $scale : 0);
        if ($isNegative) {
            $result = $result->negated();
        }
        if ($scale < 0) {
            $result = $result->multipliedBy((BigInteger::of(10))->power(-$scale));
        }
        return $result;
    }