• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2024 Google LLC.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 use super::opaque_pointee::opaque_pointee;
9 use core::ptr::NonNull;
10 
11 opaque_pointee!(upb_MiniTable);
12 pub type RawMiniTable = NonNull<upb_MiniTable>;
13 
14 opaque_pointee!(upb_MiniTableField);
15 pub type RawMiniTableField = NonNull<upb_MiniTableField>;
16 
17 extern "C" {
18     /// Finds the field with the provided number, will return NULL if no such
19     /// field is found.
20     ///
21     /// # Safety
22     /// - `m` must be legal to deref
upb_MiniTable_FindFieldByNumber( m: *const upb_MiniTable, number: u32, ) -> *const upb_MiniTableField23     pub fn upb_MiniTable_FindFieldByNumber(
24         m: *const upb_MiniTable,
25         number: u32,
26     ) -> *const upb_MiniTableField;
27 
28     /// Gets the field with the corresponding upb field index. This will never
29     /// return null: the provided number must be within bounds or else this is
30     /// UB.
31     ///
32     /// # Safety
33     /// - `m` must be legal to deref
34     /// - `number` must be a valid field index in the `m` table
upb_MiniTable_GetFieldByIndex( m: *const upb_MiniTable, number: u32, ) -> *const upb_MiniTableField35     pub fn upb_MiniTable_GetFieldByIndex(
36         m: *const upb_MiniTable,
37         number: u32,
38     ) -> *const upb_MiniTableField;
39 
40     /// Gets the sub-MiniTable associated with `f`.
41     /// # Safety
42     /// - `m` and `f` must be valid to deref
43     /// - `f` must be a mesage or map typed field associated with `m`
upb_MiniTable_SubMessage( m: *const upb_MiniTable, f: *const upb_MiniTableField, ) -> *const upb_MiniTable44     pub fn upb_MiniTable_SubMessage(
45         m: *const upb_MiniTable,
46         f: *const upb_MiniTableField,
47     ) -> *const upb_MiniTable;
48 }
49 
50 #[cfg(test)]
51 mod tests {
52     use super::*;
53     use googletest::gtest;
54 
55     #[gtest]
assert_mini_table_linked()56     fn assert_mini_table_linked() {
57         use crate::assert_linked;
58         assert_linked!(upb_MiniTable_FindFieldByNumber);
59         assert_linked!(upb_MiniTable_GetFieldByIndex);
60         assert_linked!(upb_MiniTable_SubMessage);
61     }
62 }
63