PHP code example of centraldesktop / protobuf-php

1. Go to this page and download the library: Download centraldesktop/protobuf-php 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/ */

    

centraldesktop / protobuf-php example snippets


$person = new Tutorial\Person();
$person->name = 'DrSlump';
$person->setId(12);

$book = new Tutorial\AddressBook();
$book->addPerson($person);

// Use default codec
$data = $book->serialize();

// Use custom codec
$codec = new \DrSlump\Protobuf\Codec\Json();
$data = $codec->encode($book);
// ... or ...
$data = $book->serialize($codec);