|
| 1 | +// |
| 2 | +// Copyright 2022 Google LLC |
| 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 | +#ifndef FIRSESNanoPBHelpers_h |
| 17 | +#define FIRSESNanoPBHelpers_h |
| 18 | + |
| 19 | +#import <nanopb/pb.h> |
| 20 | +#import <nanopb/pb_decode.h> |
| 21 | +#import <nanopb/pb_encode.h> |
| 22 | + |
| 23 | +NS_ASSUME_NONNULL_BEGIN |
| 24 | + |
| 25 | +// It seems impossible to specify the nullability of the `fields` parameter below, |
| 26 | +// yet the compiler complains that it's missing a nullability specifier. Google |
| 27 | +// yields no results at this time. |
| 28 | +#pragma clang diagnostic push |
| 29 | +#pragma clang diagnostic ignored "-Wnullability-completeness" |
| 30 | +NSData* _Nullable FIRSESEncodeProto(const pb_field_t fields[], |
| 31 | + const void* _Nonnull proto, |
| 32 | + NSError** error); |
| 33 | +#pragma clang diagnostic pop |
| 34 | + |
| 35 | +/// Mallocs a pb_bytes_array and copies the given NSData bytes into the bytes array. |
| 36 | +/// @note Memory needs to be freed manually, through pb_free or pb_release. |
| 37 | +/// @param data The data to copy into the new bytes array. |
| 38 | +pb_bytes_array_t* _Nullable FIRSESEncodeData(NSData* _Nullable data); |
| 39 | + |
| 40 | +/// Mallocs a pb_bytes_array and copies the given NSString's bytes into the bytes array. |
| 41 | +/// @note Memory needs to be freed manually, through pb_free or pb_release. |
| 42 | +/// @param string The string to encode as pb_bytes. |
| 43 | +pb_bytes_array_t* _Nullable FIRSESEncodeString(NSString* _Nullable string); |
| 44 | + |
| 45 | +/// Checks if 2 nanopb arrays are equal |
| 46 | +/// @param array array to check |
| 47 | +/// @param expected expected value of the array |
| 48 | +BOOL FIRSESIsPBArrayEqual(pb_bytes_array_t* _Nullable array, pb_bytes_array_t* _Nullable expected); |
| 49 | + |
| 50 | +/// Checks if a nanopb string is equal to an NSString |
| 51 | +/// @param pbString nanopb string to check |
| 52 | +/// @param str NSString that's expected |
| 53 | +BOOL FIRSESIsPBStringEqual(pb_bytes_array_t* _Nullable pbString, NSString* _Nullable str); |
| 54 | + |
| 55 | +/// Checks if a nanopb array is equal to NSData |
| 56 | +/// @param pbArray nanopb array to check |
| 57 | +/// @param data NSData that's expected |
| 58 | +BOOL FIRSESIsPBDataEqual(pb_bytes_array_t* _Nullable pbArray, NSData* _Nullable data); |
| 59 | + |
| 60 | +NS_ASSUME_NONNULL_END |
| 61 | + |
| 62 | +#endif /* FIRSESNanoPBHelpers_h */ |
0 commit comments