PHP code example of eouna / pack-binary

1. Go to this page and download the library: Download eouna/pack-binary library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eouna / pack-binary example snippets


    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);
  	

      $write->setBinaryModel(BinaryCode::LITTLE_ENDIAN | BinaryCode::BIG_ENDIAN);
    

       $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();