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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//
// Copyright (c) 2023 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

//! ⚠️ WARNING ⚠️
//!
//! This crate is intended for Zenoh's internal use.
//!
//! [Click here for Zenoh's documentation](../zenoh/index.html)
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;

pub mod common;
pub mod core;
pub mod network;
pub mod scouting;
pub mod transport;
pub mod zenoh;

use ::core::marker::PhantomData;
use zenoh_protocol::core::Reliability;

pub trait WCodec<Message, Buffer> {
    type Output;
    fn write(self, buffer: Buffer, message: Message) -> Self::Output;
}

pub trait RCodec<Message, Buffer> {
    type Error;
    fn read(self, buffer: Buffer) -> Result<Message, Self::Error>;
}

// Calculate the length of the value once serialized
pub trait LCodec<Message> {
    fn w_len(self, message: Message) -> usize;
}

#[derive(Clone, Copy)]
pub struct Zenoh080;

impl Default for Zenoh080 {
    fn default() -> Self {
        Self::new()
    }
}

impl Zenoh080 {
    pub const fn new() -> Self {
        Self
    }
}

#[derive(Clone, Copy)]
pub struct Zenoh080Header {
    pub header: u8,
    pub codec: Zenoh080,
}

impl Zenoh080Header {
    pub const fn new(header: u8) -> Self {
        Self {
            header,
            codec: Zenoh080,
        }
    }
}

#[derive(Clone, Copy)]
pub struct Zenoh080Condition {
    pub condition: bool,
    pub codec: Zenoh080,
}

impl Zenoh080Condition {
    pub const fn new(condition: bool) -> Self {
        Self {
            condition,
            codec: Zenoh080,
        }
    }
}

#[derive(Clone, Copy)]
pub struct Zenoh080Length {
    pub length: usize,
    pub codec: Zenoh080,
}

impl Zenoh080Length {
    pub const fn new(length: usize) -> Self {
        Self {
            length,
            codec: Zenoh080,
        }
    }
}

#[derive(Clone, Copy)]
pub struct Zenoh080Reliability {
    pub reliability: Reliability,
    pub codec: Zenoh080,
}

impl Zenoh080Reliability {
    pub const fn new(reliability: Reliability) -> Self {
        Self {
            reliability,
            codec: Zenoh080,
        }
    }
}

#[derive(Clone, Copy)]
pub struct Zenoh080Bounded<T> {
    _t: PhantomData<T>,
}

impl<T> Default for Zenoh080Bounded<T> {
    fn default() -> Self {
        Self::new()
    }
}

impl<T> Zenoh080Bounded<T> {
    pub const fn new() -> Self {
        Self { _t: PhantomData }
    }
}

#[cfg(feature = "shared-memory")]
#[derive(Clone, Copy)]
pub struct Zenoh080Sliced<T> {
    is_sliced: bool,
    codec: Zenoh080Bounded<T>,
}

#[cfg(feature = "shared-memory")]
impl<T> Zenoh080Sliced<T> {
    pub const fn new(is_sliced: bool) -> Self {
        Self {
            is_sliced,
            codec: Zenoh080Bounded::<T>::new(),
        }
    }
}