1 /* 2 * Copyright (C) 2020 The Android Open Source Project 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 #ifndef CHPP_SERVICES_COMMON_TYPES_H_ 18 #define CHPP_SERVICES_COMMON_TYPES_H_ 19 20 #include <stdint.h> 21 22 #include "chpp/macros.h" 23 24 /** 25 * When CHRE API structures are converted to CHPP wire format structures, this 26 * type is used to replace a pointer to an array. 27 * 28 * For example, in the CHRE API we might have something like this: 29 * struct chreBar { 30 * uint32_t baz; 31 * }; 32 * struct chreFooResult { 33 * uint8_t barCount; 34 * const struct chreBar *bars; 35 * }; 36 * 37 * To serialize this object for CHPP, we replace the pointer with a ChppOffset: 38 * 39 * struct ChppFooResult { // (packed) 40 * uint8_t barCount; 41 * struct ChppOffset bars; 42 * }; 43 * 44 * Over the wire, this structure would then immediately be followed by barCount 45 * instances of chreBar, and bars.offset would be set to sizeof(ChppFooResult) 46 * and bars.length set to barCount * sizeof(chreBar). 47 * 48 * The same applies for things like null-terminated strings (when not defined 49 * as a fixed-size nested array) - in that case, "length" includes null 50 * termination. 51 */ 52 CHPP_PACKED_START 53 struct ChppOffset { 54 //! Offset from the start of payload to the array 55 uint16_t offset; 56 57 //! Size of the array, in bytes 58 uint16_t length; 59 } CHPP_PACKED_ATTR; 60 CHPP_PACKED_END 61 62 #endif // CHPP_SERVICES_COMMON_TYPES_H_ 63