rice_c/
ffi.rs

1// Copyright (C) 2025 Matthew Waters <matthew@centricular.com>
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9//! FFI module for the raw `rice-proto` C API.
10
11#![allow(non_camel_case_types)]
12#![allow(non_upper_case_globals)]
13#![allow(unused)]
14#![allow(missing_debug_implementations)]
15#![allow(missing_docs)]
16
17use crate::mut_override;
18
19include!("bindings.rs");
20
21impl Default for RiceStreamIncomingData {
22    fn default() -> Self {
23        Self {
24            handled: false,
25            have_more_data: false,
26            data: RiceDataImpl {
27                ptr: core::ptr::null_mut(),
28                size: 0,
29            },
30        }
31    }
32}
33
34impl RiceDataImpl {
35    pub(crate) fn to_c(slice: &[u8]) -> Self {
36        Self {
37            ptr: mut_override(slice.as_ptr()),
38            size: slice.len(),
39        }
40    }
41}
42
43impl RiceData {
44    pub(crate) fn to_c_owned(slice: &[u8]) -> Self {
45        RiceData {
46            tag: RICE_DATA_OWNED,
47            field1: RiceData__bindgen_ty_1 {
48                field2: core::mem::ManuallyDrop::new(RiceData__bindgen_ty_1__bindgen_ty_2 {
49                    owned: RiceDataImpl::to_c(slice),
50                }),
51            },
52        }
53    }
54}
55
56impl RiceGatheredCandidate {
57    pub(crate) unsafe fn zeroed() -> Self {
58        unsafe {
59            RiceGatheredCandidate {
60                candidate: RiceCandidate::zeroed(),
61                turn_agent: core::ptr::null_mut(),
62            }
63        }
64    }
65}
66
67impl RiceCandidate {
68    pub(crate) unsafe fn zeroed() -> Self {
69        RiceCandidate {
70            component_id: 1,
71            candidate_type: RICE_CANDIDATE_TYPE_HOST,
72            transport_type: RICE_TRANSPORT_TYPE_UDP,
73            foundation: core::ptr::null_mut(),
74            priority: 0,
75            address: core::ptr::null(),
76            base_address: core::ptr::null(),
77            related_address: core::ptr::null(),
78            tcp_type: RICE_TCP_TYPE_NONE,
79            extensions: core::ptr::null_mut(),
80            extensions_len: 0,
81        }
82    }
83}