aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/BitOps/UnpackIntSpecifiers.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/BitOps/UnpackIntSpecifiers.php')
-rw-r--r--src/BitOps/UnpackIntSpecifiers.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/BitOps/UnpackIntSpecifiers.php b/src/BitOps/UnpackIntSpecifiers.php
new file mode 100644
index 0000000..be210f3
--- /dev/null
+++ b/src/BitOps/UnpackIntSpecifiers.php
@@ -0,0 +1,24 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Nsfisis\Waddiwasi\BitOps;
+
+enum UnpackIntSpecifiers: string
+{
+ case SignedInt8 = 'c';
+ case SignedInt16MachineOrder = 's';
+ case SignedInt32MachineOrder = 'l';
+ case UnsignedInt32LittleEndian = 'V';
+ case SignedInt64MachineOrder = 'q';
+
+ public function byteCount(): int
+ {
+ return match ($this) {
+ self::SignedInt8 => 1,
+ self::SignedInt16MachineOrder => 2,
+ self::SignedInt32MachineOrder, self::UnsignedInt32LittleEndian => 4,
+ self::SignedInt64MachineOrder => 8,
+ };
+ }
+}