zenoh_protocol/common/
mod.rs

1//
2// Copyright (c) 2023 ZettaScale Technology
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8//
9// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10//
11// Contributors:
12//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
13//
14pub mod extension;
15pub use extension::*;
16
17/*************************************/
18/*               IDS                 */
19/*************************************/
20// Inner Message IDs
21pub mod imsg {
22    // Header mask
23    pub const HEADER_BITS: u8 = 5;
24    pub const HEADER_MASK: u8 = !(0xff << HEADER_BITS);
25
26    pub const fn mid(header: u8) -> u8 {
27        header & HEADER_MASK
28    }
29
30    pub const fn flags(header: u8) -> u8 {
31        header & !HEADER_MASK
32    }
33
34    pub const fn has_flag(byte: u8, flag: u8) -> bool {
35        byte & flag != 0
36    }
37
38    pub const fn unset_flag(mut byte: u8, flag: u8) -> u8 {
39        byte &= !flag;
40        byte
41    }
42
43    pub const fn set_flag(mut byte: u8, flag: u8) -> u8 {
44        byte = unset_flag(byte, flag);
45        byte |= flag;
46        byte
47    }
48
49    pub const fn set_bitfield(mut byte: u8, value: u8, mask: u8) -> u8 {
50        byte = unset_flag(byte, mask);
51        byte |= value;
52        byte
53    }
54
55    pub const fn has_option(options: u64, flag: u64) -> bool {
56        options & flag != 0
57    }
58}