M README.md => README.md +30 -0
@@ 3,3 3,33 @@
PHP implementation of [BARE](https://baremessages.org).
Work in progress.
+
+# Support
+
+## Primitives
+
+`BARE primitive`: **BareMess class name** (php default type).
+
+* `uint`: **UInt**
+* `int`: **Integer** (int)
+* `u8`, `u16`, `u32`, `u64`: **U8**, **U16**, **U32**, **U64**
+* `i8`, `i16`, `i32`, `i64`: **I8**, **I16**, **I32**, **I64**
+* `f32`, `f64`: Not yet implemented.
+* `bool`: **Boolean** (bool)
+* `enum`: Not yet implemented, use **UInt**.
+* `string`: **Str** (string)
+* `data<length>`: Not yet implemented.
+* `data`: **Data**
+* `void`: **Nothing**
+
+All primitive types provide the following methods, which can be used as follows.
+
+```php
+use BareMess\U16;
+
+$dayNumber = U16::fromValue(366); // Create object with specific value.
+$dayNumber->set(365); // Mutator
+$mess = $dayNumber->mess(); // Convert into BARE message format.
+$day = new U16($mess); // Constructor mutates the $mess parameter
+$day->get(); // Accessor -- returns 365
+```
M src/Mutatable.php => src/Mutatable.php +1 -1
@@ 6,7 6,7 @@ trait Mutatable
{
public static function fromValue($value)
{
- $o = new self();
+ $o = new static();
$o->set($value);
return $o;
}
M tests/PrimitivesTest.php => tests/PrimitivesTest.php +3 -0
@@ 184,6 184,9 @@ class PrimitivesTest extends TestCase
$u8->set(255);
$this->assertEquals(255, $u8->get());
$this->assertEquals("\xFF", $u8->mess());
+
+ $u16 = U16::fromValue(365);
+
$mess = "\xEF\xBE\xAD\xDE";
$u32 = new U32($mess);
$this->assertEquals("", $mess);