Binary Stream Packager - a tools to handle binary data or stream
-
-
use BinaryStream\BinaryWriter; $writer = new BinaryWriter(); $writer->writeUTFString( str_repeat("It`s long string,", 200) ); $writer->writeUTFString(""); $writer->writeInt32(-90); $writer->writeDouble(800); $writer->writeFloat(3.88511321334343434324443324321); $writer->writeDouble(148.3243413243132134343213244313132); $writer->writeChar("s"); $byteWriter = new ByteWriter(); $byteWriter->writeByte(120); $byteWriter->writeInt16ToByte(65530); $byteWriter->writeInt32ToByte(1526456146); $writer->writeByteObject($byteWriter);
-
note
- the default encode method is BIG ENDIAN you can use method setBinaryModel to change it
$write->setBinaryModel(BinaryCode::LITTLE_ENDIAN | BinaryCode::BIG_ENDIAN);
- the default write flag to store file is FILE_BINARY you can use method store to change it
$writer->store(FILE_APPEND); //or $writer->store(FILE_TEXT); //or $writer->store(FILE_APPEND | LOCK_EX);
-
$reader = new BinaryReader($writer->getWriteStream()); $res[] = $reader->readUTFString(); $res[] = $reader->readUTFString(); $res[] = $reader->readInt32(); $res[] = $reader- >readDouble(); $res[] = $reader->readDouble(); $res[] = $reader->readFloat(); $res[] = $reader->readDouble(); $res[] = $reader->readChar(); $byteReader = $reader->readByByteReader(); $res[] = $byteReader->readByte(); $res[] = $byteReader->readBytesToShort(); $res[] = $byteReader->readByteToInt32();
-
use
composer require eouna/pack-binary
to install this package