/rust/registry/src/index.crates.io-1949cf8c6b5b557f/flatbuffers-25.12.19/src/get_root.rs
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2020 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::{ |
18 | | Follow, ForwardsUOffset, InvalidFlatbuffer, SkipSizePrefix, Verifiable, Verifier, |
19 | | VerifierOptions, |
20 | | }; |
21 | | |
22 | | /// Gets the root of the Flatbuffer, verifying it first with default options. |
23 | | /// Note that verification is an experimental feature and may not be maximally performant or |
24 | | /// catch every error (though that is the goal). See the `_unchecked` variants for previous |
25 | | /// behavior. |
26 | 0 | pub fn root<'buf, T>(data: &'buf [u8]) -> Result<T::Inner, InvalidFlatbuffer> |
27 | 0 | where |
28 | 0 | T: 'buf + Follow<'buf> + Verifiable, |
29 | | { |
30 | 0 | let opts = VerifierOptions::default(); |
31 | 0 | root_with_opts::<T>(&opts, data) |
32 | 0 | } Unexecuted instantiation: flatbuffers::get_root::root::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::kind_list_generated::KindList> Unexecuted instantiation: flatbuffers::get_root::root::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::value_list_generated::ValueList> Unexecuted instantiation: flatbuffers::get_root::root::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::string_range_generated::StringRange> Unexecuted instantiation: flatbuffers::get_root::root::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::argument_list_generated::ArgumentList> Unexecuted instantiation: flatbuffers::get_root::root::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::optional_value_list_generated::OptionalValueList> Unexecuted instantiation: flatbuffers::get_root::root::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::string_key_value_list_generated::StringKeyValueList> Unexecuted instantiation: flatbuffers::get_root::root::<_> |
33 | | |
34 | | #[inline] |
35 | | /// Gets the root of the Flatbuffer, verifying it first with given options. |
36 | | /// Note that verification is an experimental feature and may not be maximally performant or |
37 | | /// catch every error (though that is the goal). See the `_unchecked` variants for previous |
38 | | /// behavior. |
39 | 0 | pub fn root_with_opts<'opts, 'buf, T>( |
40 | 0 | opts: &'opts VerifierOptions, |
41 | 0 | data: &'buf [u8], |
42 | 0 | ) -> Result<T::Inner, InvalidFlatbuffer> |
43 | 0 | where |
44 | 0 | T: 'buf + Follow<'buf> + Verifiable, |
45 | | { |
46 | 0 | let mut v = Verifier::new(opts, data); |
47 | 0 | <ForwardsUOffset<T>>::run_verifier(&mut v, 0)?; |
48 | | // Safety: |
49 | | // Run verifier above |
50 | 0 | Ok(unsafe { root_unchecked::<T>(data) }) |
51 | 0 | } Unexecuted instantiation: flatbuffers::get_root::root_with_opts::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::value_generated::Value> Unexecuted instantiation: flatbuffers::get_root::root_with_opts::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::kind_generated::Kind> Unexecuted instantiation: flatbuffers::get_root::root_with_opts::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::kind_list_generated::KindList> Unexecuted instantiation: flatbuffers::get_root::root_with_opts::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::value_list_generated::ValueList> Unexecuted instantiation: flatbuffers::get_root::root_with_opts::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::string_range_generated::StringRange> Unexecuted instantiation: flatbuffers::get_root::root_with_opts::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::argument_list_generated::ArgumentList> Unexecuted instantiation: flatbuffers::get_root::root_with_opts::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::optional_value_list_generated::OptionalValueList> Unexecuted instantiation: flatbuffers::get_root::root_with_opts::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::string_key_value_list_generated::StringKeyValueList> Unexecuted instantiation: flatbuffers::get_root::root_with_opts::<_> |
52 | | |
53 | | #[inline] |
54 | | /// Gets the root of a size prefixed Flatbuffer, verifying it first with default options. |
55 | | /// Note that verification is an experimental feature and may not be maximally performant or |
56 | | /// catch every error (though that is the goal). See the `_unchecked` variants for previous |
57 | | /// behavior. |
58 | 0 | pub fn size_prefixed_root<'buf, T>(data: &'buf [u8]) -> Result<T::Inner, InvalidFlatbuffer> |
59 | 0 | where |
60 | 0 | T: 'buf + Follow<'buf> + Verifiable, |
61 | | { |
62 | 0 | let opts = VerifierOptions::default(); |
63 | 0 | size_prefixed_root_with_opts::<T>(&opts, data) |
64 | 0 | } |
65 | | |
66 | | #[inline] |
67 | | /// Gets the root of a size prefixed Flatbuffer, verifying it first with given options. |
68 | | /// Note that verification is an experimental feature and may not be maximally performant or |
69 | | /// catch every error (though that is the goal). See the `_unchecked` variants for previous |
70 | | /// behavior. |
71 | 0 | pub fn size_prefixed_root_with_opts<'opts, 'buf, T>( |
72 | 0 | opts: &'opts VerifierOptions, |
73 | 0 | data: &'buf [u8], |
74 | 0 | ) -> Result<T::Inner, InvalidFlatbuffer> |
75 | 0 | where |
76 | 0 | T: 'buf + Follow<'buf> + Verifiable, |
77 | | { |
78 | 0 | let mut v = Verifier::new(opts, data); |
79 | 0 | <SkipSizePrefix<ForwardsUOffset<T>>>::run_verifier(&mut v, 0)?; |
80 | | // Safety: |
81 | | // Run verifier above |
82 | 0 | Ok(unsafe { size_prefixed_root_unchecked::<T>(data) }) |
83 | 0 | } |
84 | | |
85 | | #[inline] |
86 | | /// Gets root for a trusted Flatbuffer. |
87 | | /// # Safety |
88 | | /// Flatbuffers accessors do not perform validation checks before accessing. Unlike the other |
89 | | /// `root` functions, this does not validate the flatbuffer before returning the accessor. Users |
90 | | /// must trust `data` contains a valid flatbuffer (e.g. b/c it was built by your software). Reading |
91 | | /// unchecked buffers may cause panics or even UB. |
92 | 0 | pub unsafe fn root_unchecked<'buf, T>(data: &'buf [u8]) -> T::Inner |
93 | 0 | where |
94 | 0 | T: Follow<'buf> + 'buf, |
95 | | { |
96 | 0 | <ForwardsUOffset<T>>::follow(data, 0) |
97 | 0 | } Unexecuted instantiation: flatbuffers::get_root::root_unchecked::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::value_generated::Value> Unexecuted instantiation: flatbuffers::get_root::root_unchecked::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::kind_generated::Kind> Unexecuted instantiation: flatbuffers::get_root::root_unchecked::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::kind_list_generated::KindList> Unexecuted instantiation: flatbuffers::get_root::root_unchecked::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::value_list_generated::ValueList> Unexecuted instantiation: flatbuffers::get_root::root_unchecked::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::string_range_generated::StringRange> Unexecuted instantiation: flatbuffers::get_root::root_unchecked::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::argument_list_generated::ArgumentList> Unexecuted instantiation: flatbuffers::get_root::root_unchecked::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::optional_value_list_generated::OptionalValueList> Unexecuted instantiation: flatbuffers::get_root::root_unchecked::<surrealdb_protocol::fb::generated::surrealdb::protocol::v_1::string_key_value_list_generated::StringKeyValueList> Unexecuted instantiation: flatbuffers::get_root::root_unchecked::<_> |
98 | | |
99 | | #[inline] |
100 | | /// Gets root for a trusted, size prefixed, Flatbuffer. |
101 | | /// # Safety |
102 | | /// Flatbuffers accessors do not perform validation checks before accessing. Unlike the other |
103 | | /// `root` functions, this does not validate the flatbuffer before returning the accessor. Users |
104 | | /// must trust `data` contains a valid flatbuffer (e.g. b/c it was built by your software). Reading |
105 | | /// unchecked buffers may cause panics or even UB. |
106 | 0 | pub unsafe fn size_prefixed_root_unchecked<'buf, T>(data: &'buf [u8]) -> T::Inner |
107 | 0 | where |
108 | 0 | T: Follow<'buf> + 'buf, |
109 | | { |
110 | 0 | <SkipSizePrefix<ForwardsUOffset<T>>>::follow(data, 0) |
111 | 0 | } |