• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use crate::{unwrap, PanicReason};
16 use np_ffi_core::common::*;
17 use np_ffi_core::credentials::CredentialBook;
18 use np_ffi_core::deserialize::v0::*;
19 use np_ffi_core::deserialize::v1::*;
20 use np_ffi_core::deserialize::*;
21 use np_ffi_core::utils::FfiEnum;
22 
23 mod v0;
24 mod v1;
25 
26 /// Attempts to deserialize an advertisement with the given service-data
27 /// payload (presumed to be under the NP service UUID) using credentials
28 /// pulled from the given credential-book.
29 #[no_mangle]
np_ffi_deserialize_advertisement( adv_payload: RawAdvertisementPayload, credential_book: CredentialBook, ) -> DeserializeAdvertisementResult30 pub extern "C" fn np_ffi_deserialize_advertisement(
31     adv_payload: RawAdvertisementPayload,
32     credential_book: CredentialBook,
33 ) -> DeserializeAdvertisementResult {
34     deserialize_advertisement(&adv_payload, credential_book)
35 }
36 
37 /// Gets the tag of a `DeserializeAdvertisementResult` tagged-union.
38 #[no_mangle]
np_ffi_DeserializeAdvertisementResult_kind( result: DeserializeAdvertisementResult, ) -> DeserializeAdvertisementResultKind39 pub extern "C" fn np_ffi_DeserializeAdvertisementResult_kind(
40     result: DeserializeAdvertisementResult,
41 ) -> DeserializeAdvertisementResultKind {
42     result.kind()
43 }
44 
45 /// Casts a `DeserializeAdvertisementResult` to the `V0` variant, panicking in the
46 /// case where the passed value is of a different enum variant.
47 #[no_mangle]
np_ffi_DeserializeAdvertisementResult_into_V0( result: DeserializeAdvertisementResult, ) -> DeserializedV0Advertisement48 pub extern "C" fn np_ffi_DeserializeAdvertisementResult_into_V0(
49     result: DeserializeAdvertisementResult,
50 ) -> DeserializedV0Advertisement {
51     unwrap(result.into_v0(), PanicReason::EnumCastFailed)
52 }
53 
54 /// Casts a `DeserializeAdvertisementResult` to the `V1` variant, panicking in the
55 /// case where the passed value is of a different enum variant.
56 #[no_mangle]
np_ffi_DeserializeAdvertisementResult_into_V1( result: DeserializeAdvertisementResult, ) -> DeserializedV1Advertisement57 pub extern "C" fn np_ffi_DeserializeAdvertisementResult_into_V1(
58     result: DeserializeAdvertisementResult,
59 ) -> DeserializedV1Advertisement {
60     unwrap(result.into_v1(), PanicReason::EnumCastFailed)
61 }
62 
63 /// Deallocates any internal data referenced by a `DeserializeAdvertisementResult`. This should only
64 /// be used if into_V0 or into_V1, have not been called yet as it shares the same underlying
65 /// resource.
66 #[no_mangle]
np_ffi_deallocate_deserialize_advertisement_result( result: DeserializeAdvertisementResult, ) -> DeallocateResult67 pub extern "C" fn np_ffi_deallocate_deserialize_advertisement_result(
68     result: DeserializeAdvertisementResult,
69 ) -> DeallocateResult {
70     result.deallocate()
71 }
72 
73 /// Deallocates any internal data referenced by a `DeserializedV0Advertisement`
74 #[no_mangle]
np_ffi_deallocate_deserialized_V0_advertisement( adv: DeserializedV0Advertisement, ) -> DeallocateResult75 pub extern "C" fn np_ffi_deallocate_deserialized_V0_advertisement(
76     adv: DeserializedV0Advertisement,
77 ) -> DeallocateResult {
78     adv.deallocate()
79 }
80 
81 /// Deallocates any internal data referenced by a `DeserializedV1Advertisement`
82 #[no_mangle]
np_ffi_deallocate_deserialized_V1_advertisement( adv: DeserializedV1Advertisement, ) -> DeallocateResult83 pub extern "C" fn np_ffi_deallocate_deserialized_V1_advertisement(
84     adv: DeserializedV1Advertisement,
85 ) -> DeallocateResult {
86     adv.deallocate()
87 }
88