Protocol
Protocol
- Full name:
\Hazaar\Application\Protocol
Properties
typeCodes
public static array<int,string> $typeCodes
- This property is static.
id
private int $id
last_error
private string $last_error
encoded
private bool $encoded
Methods
__construct
public __construct(int $id, bool $encoded = true): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$id | int | |
$encoded | bool |
getLastError
Returns the last error message.
public getLastError(): string
Return Value:
the last error message
encoded
Returns whether the application protocol is encoded.
public encoded(): bool
Return Value:
true if the application protocol is encoded, false otherwise
check
Checks that a protocol message type is valid and returns it's numeric value.
public check(int|string $type): bool|int
Parameters:
Parameter | Type | Description |
---|---|---|
$type | int|string | If $type is a string, it is checked and if valid then it's numeric value is returned. If $type is an integer it will be returned back if valid. If either is not valid then false is returned. |
Return Value:
The integer value of the message type. False if the type is not valid.
getType
Get the type code for a given name.
public getType(string $name): false|int
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | the name of the protocol |
Return Value:
the type code if found, otherwise false
getTypeName
Returns the name of the type based on the given type ID.
public getTypeName(int $type): bool|string
Parameters:
Parameter | Type | Description |
---|---|---|
$type | int | the type ID |
Return Value:
the name of the type
encode
Encodes the payload into a string representation.
public encode(int $type, mixed $payload = null): string
Parameters:
Parameter | Type | Description |
---|---|---|
$type | int | the type of the payload |
$payload | mixed | the payload to be encoded |
Return Value:
the encoded payload as a string
decode
Decodes a packet and extracts the payload and time information.
public decode(string $packet, mixed& $payload = null, int& $time = null): bool|string
Parameters:
Parameter | Type | Description |
---|---|---|
$packet | string | the packet to decode |
$payload | mixed | The variable to store the payload data. Defaults to null. |
$time | int | The variable to store the time data. Defaults to null. |
Return Value:
the type name of the decoded packet
error
Sets the last error message and returns false.
private error(string $msg): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$msg | string | The error message to be set. |
Return Value:
Always returns false.
Automatically generated on 2024-11-14