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
16use crate::mut_override;
17
18include!("bindings.rs");
19
20impl Default for RiceStreamIncomingData {
21    fn default() -> Self {
22        Self {
23            handled: false,
24            have_more_data: false,
25            data: RiceDataImpl {
26                ptr: core::ptr::null_mut(),
27                size: 0,
28            },
29        }
30    }
31}
32
33impl RiceDataImpl {
34    pub(crate) fn to_c(slice: &[u8]) -> Self {
35        Self {
36            ptr: mut_override(slice.as_ptr()),
37            size: slice.len(),
38        }
39    }
40}
41
42impl RiceData {
43    pub(crate) fn to_c_owned(slice: &[u8]) -> Self {
44        RiceData {
45            tag: RICE_DATA_OWNED,
46            field1: RiceData__bindgen_ty_1 {
47                field2: core::mem::ManuallyDrop::new(RiceData__bindgen_ty_1__bindgen_ty_2 {
48                    owned: RiceDataImpl::to_c(slice),
49                }),
50            },
51        }
52    }
53}
54
55impl RiceGatheredCandidate {
56    pub(crate) unsafe fn zeroed() -> Self {
57        RiceGatheredCandidate {
58            candidate: RiceCandidate::zeroed(),
59            turn_agent: core::ptr::null_mut(),
60        }
61    }
62}
63
64impl RiceCandidate {
65    pub(crate) unsafe fn zeroed() -> Self {
66        RiceCandidate {
67            component_id: 1,
68            candidate_type: RICE_CANDIDATE_TYPE_HOST,
69            transport_type: RICE_TRANSPORT_TYPE_UDP,
70            foundation: core::ptr::null_mut(),
71            priority: 0,
72            address: core::ptr::null(),
73            base_address: core::ptr::null(),
74            related_address: core::ptr::null(),
75            tcp_type: RICE_TCP_TYPE_NONE,
76            extensions: core::ptr::null_mut(),
77            extensions_len: 0,
78        }
79    }
80}