1. Go to this page and download the library: Download sqrt-cat/proto-bin 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/ */
sqrt-cat / proto-bin example snippets
use SqrtCat\ProtoBin\ProtocolMessage;
use SqrtCat\ProtoBin\ProtocolType;
class RegisterRequest extends ProtocolMessage
{
public $account;
public $password;
public $age;
// 参数项位序 accountBin passwordBin ageBin
public static $paramNameMapping = [
0 => 'account',
1 => 'password',
2 => 'age',
];
// 参数类型
public static $paramProtocolTypeMapping = [
'account' => ProtocolType::TYPE_STRING,
'password' => ProtocolType::TYPE_STRING,
'age' => ProtocolType::TYPE_TINYINT,
];
public function setAccount($account)
{
$paramType = static::getParamType('account');
$this->accountBin = ProtocolType::pack($account, $paramType);
}
public function getAccount()
{
return $this->account;
}
public function setPassword($password)
{
$paramType = static::getParamType('password');
$this->passwordBin = ProtocolType::pack($password, $paramType);
}
public function getPassword()
{
return $this->password;
}
public function setAge($age)
{
$paramType = static::getParamType('age');
$this->ageBin = ProtocolType::pack($age, $paramType);
}
public function getAge()
{
return $this->age;
}
}