mattiabasone commented on code in PR #3526:
URL: https://github.com/apache/avro/pull/3526#discussion_r2454929761


##########
lang/php/lib/Datum/AvroIOBinaryEncoder.php:
##########
@@ -187,4 +188,46 @@ public function writeBytes($bytes)
         $this->writeLong(strlen($bytes));
         $this->write($bytes);
     }
+
+    public function writeDecimal($decimal, int $scale, int $precision): void
+    {
+        if (!is_numeric($decimal)) {
+            throw new AvroException('Decimal must be a numeric value');
+        }
+
+        $value = $decimal * (10 ** $scale);
+        if (!is_int($value)) {
+            $value = (int) round($value);
+        }
+        if (abs($value) > (10 ** $precision - 1)) {
+            throw new AvroException('Decimal value is out of range');
+        }
+
+        $packed = pack('J', $value);

Review Comment:
   [pack](https://www.php.net/manual/it/function.pack.php) documentation says 
something different
   > J => unsigned long long (always 64 bit, big endian byte order)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to