Coverage Report

Created: 2026-09-19 07:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/flatbuffers-25.12.19/src/table.rs
Line
Count
Source
1
/*
2
 * Copyright 2018 Google Inc. All rights reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
use crate::follow::Follow;
18
use crate::primitives::*;
19
use crate::vtable::VTable;
20
21
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
22
pub struct Table<'a> {
23
    buf: &'a [u8],
24
    loc: usize,
25
}
26
27
impl<'a> Table<'a> {
28
    #[inline]
29
0
    pub fn buf(&self) -> &'a [u8] {
30
0
        self.buf
31
0
    }
32
33
    #[inline]
34
0
    pub fn loc(&self) -> usize {
35
0
        self.loc
36
0
    }
37
38
    /// # Safety
39
    ///
40
    /// `buf` must contain a `soffset_t` at `loc`, which points to a valid vtable
41
    #[inline]
42
0
    pub unsafe fn new(buf: &'a [u8], loc: usize) -> Self {
43
0
        Table { buf, loc }
44
0
    }
Unexecuted instantiation: <flatbuffers::table::Table>::new
Unexecuted instantiation: <flatbuffers::table::Table>::new
Unexecuted instantiation: <flatbuffers::table::Table>::new
Unexecuted instantiation: <flatbuffers::table::Table>::new
45
46
    #[inline]
47
0
    pub fn vtable(&self) -> VTable<'a> {
48
        // Safety:
49
        // Table::new is created with a valid buf and location
50
0
        unsafe { <BackwardsSOffset<VTable<'a>>>::follow(self.buf, self.loc) }
51
0
    }
Unexecuted instantiation: <flatbuffers::table::Table>::vtable
Unexecuted instantiation: <flatbuffers::table::Table>::vtable
52
53
    /// Retrieves the value at the provided `slot_byte_loc` returning `default`
54
    /// if no value present
55
    ///
56
    /// # Safety
57
    ///
58
    /// The value of the corresponding slot must have type T
59
    #[inline]
60
0
    pub unsafe fn get<T: Follow<'a> + 'a>(
61
0
        &self,
62
0
        slot_byte_loc: VOffsetT,
63
0
        default: Option<T::Inner>,
64
0
    ) -> Option<T::Inner> {
65
0
        let o = self.vtable().get(slot_byte_loc) as usize;
66
0
        if o == 0 {
67
0
            return default;
68
0
        }
69
0
        Some(<T>::follow(self.buf, self.loc + o))
70
0
    }
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::table::Table>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::kind_generated::Kind>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::point_generated::Point>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::value_generated::Value>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::polygon_generated::Polygon>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::argument_generated::Argument>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::geometry_generated::Geometry>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::key_value_generated::KeyValue>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::line_string_generated::LineString>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::object_field_generated::ObjectField>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::literal_object_generated::LiteralObject>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::optional_value_generated::OptionalValue>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::string_key_value_generated::StringKeyValue>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<flatbuffers::primitives::ForwardsUOffset<&str>>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::geometry_kind_type_generated::GeometryKindType>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<flatbuffers::vector::Vector<u8>>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::kind_generated::Kind>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::value_generated::Value>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::line_string_generated::LineString>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::record_id_key_generated::RecordIdKey>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::uint_64_value_generated::UInt64Value>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<flatbuffers::primitives::ForwardsUOffset<&str>>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::kind_type_generated::KindType>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::value_type_generated::ValueType>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::value_bound_generated::ValueBound>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::literal_type_generated::LiteralType>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::geometry_type_generated::GeometryType>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::string_bound_tag_generated::StringBoundTag>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::record_id_key_type_generated::RecordIdKeyType>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::record_id_key_bound_generated::RecordIdKeyBound>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<bool>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<f64>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<u32>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<i64>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<u64>
Unexecuted instantiation: <flatbuffers::table::Table>::get::<_>
71
}
72
73
impl<'a> Follow<'a> for Table<'a> {
74
    type Inner = Table<'a>;
75
    #[inline]
76
0
    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
77
0
        Table { buf, loc }
78
0
    }
Unexecuted instantiation: <flatbuffers::table::Table as flatbuffers::follow::Follow>::follow
Unexecuted instantiation: <flatbuffers::table::Table as flatbuffers::follow::Follow>::follow
79
}
80
81
/// Returns true if data contains a prefix of `ident`
82
#[inline]
83
0
pub fn buffer_has_identifier(data: &[u8], ident: &str, size_prefixed: bool) -> bool {
84
0
    assert_eq!(ident.len(), FILE_IDENTIFIER_LENGTH);
85
86
0
    let got = if size_prefixed {
87
0
        assert!(data.len() >= SIZE_SIZEPREFIX + SIZE_UOFFSET + FILE_IDENTIFIER_LENGTH);
88
        // Safety:
89
        // Verified data has sufficient bytes
90
0
        unsafe { <SkipSizePrefix<SkipRootOffset<FileIdentifier>>>::follow(data, 0) }
91
    } else {
92
0
        assert!(data.len() >= SIZE_UOFFSET + FILE_IDENTIFIER_LENGTH);
93
        // Safety:
94
        // Verified data has sufficient bytes
95
0
        unsafe { <SkipRootOffset<FileIdentifier>>::follow(data, 0) }
96
    };
97
98
0
    ident.as_bytes() == got
99
0
}