zenoh_shm/api/provider/
chunk.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//
14
15use std::num::NonZeroUsize;
16
17use crate::api::common::types::{ChunkID, PtrInSegment, SegmentID};
18
19/// Uniquely identifies the particular chunk within particular segment
20#[zenoh_macros::unstable_doc]
21#[derive(Clone, Debug, PartialEq, Eq)]
22#[stabby::stabby]
23pub struct ChunkDescriptor {
24    pub segment: SegmentID,
25    pub chunk: ChunkID,
26    pub len: NonZeroUsize,
27}
28
29impl ChunkDescriptor {
30    /// Create a new Chunk Descriptor
31    #[zenoh_macros::unstable_doc]
32    pub fn new(segment: SegmentID, chunk: ChunkID, len: NonZeroUsize) -> Self {
33        Self {
34            segment,
35            chunk,
36            len,
37        }
38    }
39}
40
41/// A recently-allocated chunk.
42#[zenoh_macros::unstable_doc]
43pub struct AllocatedChunk {
44    pub descriptor: ChunkDescriptor,
45    pub data: PtrInSegment,
46}
47
48impl AllocatedChunk {
49    /// Create a new Allocated Chunk
50    #[zenoh_macros::unstable_doc]
51    pub fn new(descriptor: ChunkDescriptor, data: PtrInSegment) -> Self {
52        Self { descriptor, data }
53    }
54}