datex_core/global/
dxb_block.rs

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
use num_enum::TryFromPrimitive;

use crate::datex_values::Endpoint;


pub struct DXBBlock {
	pub header: DXBHeader
}

#[derive(Debug, Clone, PartialEq)]
pub struct DXBHeader {
	pub version: u8,

	pub size: u16,

	pub signed: bool,
	pub encrypted: bool,

	pub timestamp: u64,

	pub scope_id: u32,
	pub block_index: u16,
	pub block_increment: u16,
	pub block_type: DXBBlockType,
	pub flags: HeaderFlags,

	pub routing: RoutingInfo
}

#[derive(Debug, Clone, Copy, PartialEq, TryFromPrimitive)]
#[repr(u8)]
pub enum DXBBlockType {
	REQUEST     = 0, // default datex request
    RESPONSE    = 1, // response to a request (can be empty)

    DATA        = 2, // data only (limited execution permission)
    TMP_SCOPE   = 3, // resettable scope
    
    LOCAL       = 4, // default datex request, but don't want a response (use for <Function> code blocks, ....), must be sent and executed on same endpoint

    HELLO       = 5, // info message that endpoint is online
    DEBUGGER    = 6, // get a debugger for a scope
    SOURCE_MAP  = 7, // send a source map for a scope
    UPDATE      = 8, // like normal request, but don't propgate updated pointer values back to sender (prevent recursive loop)
}

#[derive(Debug, Clone, PartialEq)]
pub struct HeaderFlags {
	pub allow_execute: bool,
	pub end_of_scope: bool,
	pub device_type: u8
}

#[derive(Debug, Clone, PartialEq)]
pub struct RoutingInfo {
	pub ttl: u8,
	pub priority: u8,

	pub sender: Option<Endpoint>,
	// pub receivers: Disjunction<Endpoint>
}