-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageWireFormat.php
More file actions
79 lines (66 loc) · 2.13 KB
/
MessageWireFormat.php
File metadata and controls
79 lines (66 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
declare(strict_types=1);
/*
* This file is a part of the DiscordPHP-RFC9420 project.
*
* Copyright (c) 2026-present Valithor Obsidion <valithor@discordphp.org>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/
namespace MLS\Enums;
/**
* MLS Wire Formats (RFC 9420 - Section 17.2, Table 8).
* Numeric values match the RFC registry (two-byte identifiers).
*/
final class MessageWireFormat
{
public const RESERVED = 0x0000;
public const MLS_PUBLIC_MESSAGE = 0x0001;
public const MLS_PRIVATE_MESSAGE = 0x0002;
public const MLS_WELCOME = 0x0003;
public const MLS_GROUP_INFO = 0x0004;
public const MLS_KEY_PACKAGE = 0x0005;
public const PRIVATE_USE_START = 0xF000;
public const PRIVATE_USE_END = 0xFFFF;
protected const NAME_MAP = [
self::RESERVED => 'reserved',
self::MLS_PUBLIC_MESSAGE => 'mls_public_message',
self::MLS_PRIVATE_MESSAGE => 'mls_private_message',
self::MLS_WELCOME => 'mls_welcome',
self::MLS_GROUP_INFO => 'mls_group_info',
self::MLS_KEY_PACKAGE => 'mls_key_package',
];
protected const RECOMMENDED = [
self::MLS_PUBLIC_MESSAGE => true,
self::MLS_PRIVATE_MESSAGE => true,
self::MLS_WELCOME => true,
self::MLS_GROUP_INFO => true,
self::MLS_KEY_PACKAGE => true,
];
public function __construct()
{
}
public static function nameOf(int $value): ?string
{
if (isset(self::NAME_MAP[$value])) {
return self::NAME_MAP[$value];
}
if ($value >= self::PRIVATE_USE_START && $value <= self::PRIVATE_USE_END) {
return 'private_use';
}
return null;
}
/**
* Whether the wire format is recommended in the RFC.
* Returns true/false or null for values without a recommendation.
*/
public static function isRecommended(int $value): ?bool
{
return self::RECOMMENDED[$value] ?? null;
}
public static function isPrivateUse(int $value): bool
{
return $value >= self::PRIVATE_USE_START && $value <= self::PRIVATE_USE_END;
}
}