-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_base.lua
More file actions
46 lines (35 loc) · 1.1 KB
/
message_base.lua
File metadata and controls
46 lines (35 loc) · 1.1 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
--- A base class for all messages
-- @copyright (c) 2016 Russell Haley
-- @license FreeBSD License. See License.txt
--- The base message for all communications.
local message = {}
--- Sequence number from 0 to 255
message.sequence = 0
--- Unique Client ID
message.client_id = 0
--- Message Unique Identifier
message.uuid = "0-0-0-0"
--- Source Address
message.source = ""
--- Destination Address
message.destination = ""
--- Type of message
message.type = ""
--- The message specific contents of a transmission
message.body = {}
--- Returns a new message.
local function New(t)
if t then
if t.client_id then message.initiator = t.client_id end;
if t.uuid then message.uuid = t.uuid end;
if t.sequence and tonumber(t.sequence) then
message.sequence = t.sequence +1
if message.sequence > 255 then message.sequence = 1 end;
end;
if t.source then message.destination = t.source end;
if t.destination then message.source = t.destination end;
if t.type then message.type = t.type end;
end
return message
end
return { New = New }