zenoh_flow_commons/
shared_memory.rs

1//
2// Copyright (c) 2021 - 2024 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//
14
15use std::fmt::Display;
16
17use crate::deserialize::{deserialize_size, deserialize_time};
18use serde::{Deserialize, Serialize};
19
20/// Structure to configure how Zenoh-Flow uses the [shared memory](https://docs.rs/zenoh-shm/0.10.1-rc/zenoh_shm/)
21/// feature provided by Zenoh.
22///
23/// This configuration is applied on a link basis
24///
25/// A Zenoh-Flow runtime can be configured to always attempt to send data through shared-memory first. When this feature
26/// is enabled this structure allows tweaking two aspects: (i) the size of the shared memory buffer Zenoh should
27/// allocate and (ii) the back-off period.
28///
29///
30#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
31pub struct SharedMemoryConfiguration {
32    /// Size, converted in bytes, of the entire shared memory buffer.
33    #[serde(deserialize_with = "deserialize_size")]
34    pub size: usize,
35    /// Duration, converted in nanoseconds, to wait before retrying the last operation.
36    #[serde(deserialize_with = "deserialize_time")]
37    pub backoff: u64,
38}
39
40// TODO@J-Loudet
41impl Display for SharedMemoryConfiguration {
42    fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        todo!()
44    }
45}