@@ 4,6 4,18 @@ namespace BareMess;
class Bare
{
+ public static function construct(& $mess, $startingValue)
+ {
+ switch(gettype($startingValue)) {
+ case 'string': // string
+ // TODO: Use uint for string's length.
+ $length = (new U8($mess))->get();
+ $val = substr($mess, 0, $length);
+ $mess = substr($mess, $length);
+ return $val;
+ };
+ }
+
public static function mess($value): string
{
switch(gettype($value)) {
@@ 2,6 2,7 @@
namespace BareMess\Tests;
+use BareMess\Bare;
use BareMess\Example\PublicKey;
use BareMess\{I8,I16,I32,I64};
use BareMess\{U8,U16,U32,U64};
@@ 57,6 58,20 @@ class PrimitivesTest extends TestCase
$this->assertEquals("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", $i64->mess());
}
+ public function testString()
+ {
+ $mess = chr(5) . "hello" . chr(7) . " world!";
+ $string1 = Bare::construct($mess, '');
+ $string2 = Bare::construct($mess, '');
+ $this->assertEquals("", $mess);
+ $this->assertEquals("hello", $string1);
+ $this->assertEquals(" world!", $string2);
+ $mess = Bare::mess($string1, '');
+ $mess .= Bare::mess($string2, '');
+ $this->assertEquals(chr(5) . "hello" . chr(7) . " world!", $mess);
+ // TODO: Test strings longer than 127 characters
+ }
+
public function testUs()
{
$u8 = new U8();