fidl_next_codec/wire/vec/
raw.rs1use core::mem::MaybeUninit;
6use core::ptr::slice_from_raw_parts_mut;
7
8use munge::munge;
9
10use crate::{WirePointer, WireU64, ZeroPadding};
11
12#[repr(C)]
13pub struct RawWireVector<T> {
14 pub len: WireU64,
15 pub ptr: WirePointer<T>,
16}
17
18unsafe impl<T> ZeroPadding for RawWireVector<T> {
19 #[inline]
20 fn zero_padding(_: &mut MaybeUninit<Self>) {
21 }
23}
24
25unsafe impl<T: Send> Send for RawWireVector<T> {}
28
29unsafe impl<T: Sync> Sync for RawWireVector<T> {}
31
32impl<T> RawWireVector<T> {
33 pub fn encode_present(out: &mut MaybeUninit<Self>, len: u64) {
34 munge!(let Self { len: encoded_len, ptr } = out);
35 encoded_len.write(WireU64(len));
36 WirePointer::encode_present(ptr);
37 }
38
39 pub fn encode_absent(out: &mut MaybeUninit<Self>) {
40 munge!(let Self { len, ptr } = out);
41 len.write(WireU64(0));
42 WirePointer::encode_absent(ptr);
43 }
44
45 pub fn len(&self) -> u64 {
46 *self.len
47 }
48
49 pub fn as_ptr(&self) -> *mut T {
50 self.ptr.as_ptr()
51 }
52
53 pub fn as_slice_ptr(&self) -> *mut [T] {
54 slice_from_raw_parts_mut(self.as_ptr(), self.len() as usize)
55 }
56}