Protocol
About 1 min
Protocol
Hazaar Application Protocol Class
The Application Protocol is a simple protocol developed to allow communication between parts of the Hazaar framework over the wire or other IO interfaces. It allows common information to be encoded/decoded between endpoints.
Properties
typeCodes
public array $typeCodes = array (
0 => 'DEBUG',
1 => NULL,
2 => NULL,
3 => NULL,
4 => NULL,
5 => NULL,
6 => NULL,
7 => NULL,
8 => NULL,
9 => NULL,
10 => NULL,
11 => NULL,
12 => NULL,
13 => NULL,
14 => NULL,
15 => NULL,
16 => NULL,
17 => NULL,
18 => NULL,
19 => NULL,
20 => NULL,
21 => NULL,
22 => NULL,
23 => NULL,
24 => NULL,
25 => NULL,
26 => NULL,
27 => NULL,
28 => NULL,
29 => NULL,
30 => NULL,
31 => NULL,
32 => NULL,
33 => NULL,
34 => NULL,
35 => NULL,
36 => NULL,
37 => NULL,
38 => NULL,
39 => NULL,
40 => NULL,
41 => NULL,
42 => NULL,
43 => NULL,
44 => NULL,
)
id
private int $id
last_error
private string $last_error
encoded
private bool $encoded = true
Methods
__construct
public __construct(int $id, bool $encoded = true): void
Parameters
Parameter | Type | Description |
---|---|---|
$id | int | |
$encoded | bool |
getLastError
Returns the last error message.
public getLastError(): string
encoded
Returns whether the application protocol is encoded.
public encoded(): bool
check
Checks that a protocol message type is valid and returns it's numeric value.
public check(string $type): int
Parameters
Parameter | Type | Description |
---|---|---|
$type | 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. |
getType
Get the type code for a given name.
public getType(string $name): int
Parameters
Parameter | Type | Description |
---|---|---|
$name | string | the name of the protocol |
getTypeName
Returns the name of the type based on the given type ID.
public getTypeName(int $type): string
Parameters
Parameter | Type | Description |
---|---|---|
$type | int | the type ID |
encode
Encodes the payload into a string representation.
public encode(int $type, mixed $payload): ?string
Parameters
Parameter | Type | Description |
---|---|---|
$type | int | the type of the payload |
$payload | mixed | the payload to be encoded |
decode
Decodes a packet and extracts the payload and time information.
public decode(string $packet, mixed $payload, ?int $time): string
Parameters
Parameter | Type | Description |
---|---|---|
$packet | string | the packet to decode |
$payload | mixed | |
$time | int |
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 |
Generated by Hazaar API Doc Generator