file_ref.anubis
3 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
80
81
82
83
84
85
86
87
88
89
/*
* Created by 伝作 (Densaku).
* Types & Messages generator written by フランスのトトロ aka (David RENÉ)
* Date: 2019-05-17
* Time: 19:05:20
*
*/
transmit system/muscle.anubis
transmit system/convert.anubis
transmit tools/basis.anubis
transmit types/generated/mime.anubis
public type File_ref:
file_ref(
String path, //access ptah to the file on the original machine
String name, //name of the file
MIME mime, //mime type of the file
String key, //key is a SHA1 gave by sender to certify it when it will be downloaded
Int size //size of the file in Bytes
)
.
File_ref message format
=======================
public define Message
to_Message
(
File_ref _file_ref
)=
with _file_ref_message = message((Word32)0), //
forget(add_string(_file_ref_message, "__TYPE__", "File_ref"));
if _file_ref is
{
//Alternative file_ref
file_ref(_path, _name, _mime, _key, _size) then
forget(add_string(_file_ref_message, "__TYPE_ALT__", "file_ref"));
// [type = String] file_ref.path
forget(add_string(_file_ref_message, "path", _path));
// [type = String] file_ref.name
forget(add_string(_file_ref_message, "name", _name));
// [type = MIME] file_ref.mime
forget(add_message(_file_ref_message, "mime", to_Message(_mime)));
// [type = String] file_ref.key
forget(add_string(_file_ref_message, "key", _key));
// [type = Int] file_ref.size
forget(add_string(_file_ref_message, "size", to_String(_size))),
};
_file_ref_message
.
public define Maybe(File_ref)
from_Message
(
Message _file_ref_message
)=
if find_string(_file_ref_message, "__TYPE__") is {failure then failure, success(__type__) then
if find_string(_file_ref_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then
if __type__ = "File_ref" then
//Alternative file_ref
if __type_alt__ = "file_ref" then //Alternative file_ref
// [type = String] file_ref.path
if find_string(_file_ref_message, "path") is {failure then failure, success(_path_) then
// [type = String] file_ref.name
if find_string(_file_ref_message, "name") is {failure then failure, success(_name_) then
// [type = MIME] file_ref.mime
if find_message(_file_ref_message, "mime") is {failure then failure, success(_mime__msg) then
if (Maybe(MIME))from_Message(_mime__msg) is {failure then failure, success(_mime_) then
// [type = String] file_ref.key
if find_string(_file_ref_message, "key") is {failure then failure, success(_key_) then
// [type = Int] file_ref.size
if find_string(_file_ref_message, "size") is {failure then failure, success(__size_) then
if decimal_scan(__size_) is { failure then failure, success(_size_) then
success(file_ref(_path_, _name_, _mime_, _key_, _size_))
}}}}}}}
else
failure //No valid Alternative found !
else
failure //Type not found in message !
}}
.