1 #pragma once
2 #include <cstddef>
3 #include <cstdint>
4 
5 /* Type definitions */
6 #ifdef ASTRON_128BIT_CHANNELS
7 #include "util/uint128.h"
8 typedef uint128_t channel_t;
9 typedef uint64_t doid_t;
10 typedef uint64_t zone_t;
11 #else
12 typedef uint64_t channel_t;
13 typedef uint32_t doid_t;
14 typedef uint32_t zone_t;
15 #endif
16 
17 /* Type limits */
18 const channel_t CHANNEL_MAX = (channel_t)(-1);
19 const doid_t DOID_MAX = (doid_t)(-1);
20 const zone_t ZONE_MAX = (zone_t)(-1);
21 const size_t ZONE_BITS = sizeof(zone_t) * 8;
22 
23 /* DoId constants */
24 const doid_t INVALID_DO_ID = 0;
25 
26 /* Channel constants */
27 const channel_t INVALID_CHANNEL = 0;
28 const channel_t CONTROL_MESSAGE = 1;
29 const channel_t BCHAN_CLIENTS = 10;
30 const channel_t BCHAN_STATESERVERS = 12;
31 const channel_t BCHAN_DBSERVERS = 13;
32 const channel_t PARENT_PREFIX = (channel_t(1) << ZONE_BITS);
33 const channel_t DATABASE_PREFIX = (channel_t(2) << ZONE_BITS);
34 
35 /* Channel building methods */
location_as_channel(doid_t parent,zone_t zone)36 inline channel_t location_as_channel(doid_t parent, zone_t zone)
37 {
38     return (channel_t(parent) << ZONE_BITS) | channel_t(zone);
39 }
parent_to_children(doid_t parent)40 inline channel_t parent_to_children(doid_t parent)
41 {
42     return PARENT_PREFIX | channel_t(parent);
43 }
database_to_object(doid_t object)44 inline channel_t database_to_object(doid_t object)
45 {
46     return DATABASE_PREFIX | channel_t(object);
47 }
48