1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 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 16 /** 17 * @addtogroup Bluetooth 18 * @{ 19 * 20 * @brief Bluetooth Basic tool library, This file is part of BTStack. 21 * Data Struct buffer declarations. 22 * 23 * @since 1.0 24 * @version 1.0 25 */ 26 27 #ifndef BUFFER_H 28 #define BUFFER_H 29 30 #include <stddef.h> 31 #include <stdint.h> 32 33 #include "btstack.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 typedef struct Buffer Buffer; 40 41 /** 42 * @brief Malloc new fixed size Buffer. 43 * 44 * @param size Buffer size. 45 * @return Buffer pointer. 46 * @since 1.0 47 * @version 1.0 48 */ 49 BTSTACK_API Buffer *BufferMalloc(uint32_t size); 50 51 /** 52 * @brief Copy malloc new Buffer by Existing Buffer. Do not copy Data. 53 * 54 * @param buf Buffer pointer. 55 * @return Buffer pointer. 56 * @since 1.0 57 * @version 1.0 58 */ 59 BTSTACK_API Buffer *BufferRefMalloc(const Buffer *buf); 60 61 /** 62 * @brief 63 * Slice from Existing Buffer's offset, slice length is size. 64 * 65 * @param[in] buf Buffer pointer. 66 * @param[in] offset 67 * @param[in] size Slice Buffer size. 68 * @return Slice Buffer pointer. 69 */ 70 71 /** 72 * @brief Slice new Buffer from Existing Buffer. Do not copy Data. 73 * 74 * @param buf Buffer pointer. 75 * @param offset Offset relative to old buffer. 76 * @param size Target buffer size. 77 * @return Buffer pointer. 78 * @since 1.0 79 * @version 1.0 80 */ 81 BTSTACK_API Buffer *BufferSliceMalloc(const Buffer *buf, uint32_t offset, uint32_t size); 82 83 /** 84 * @brief Resize Buffer. 85 * 86 * @param buf Buffer pointer. 87 * @param offset Offset buffer offset 88 * @param size Target size. 89 * @return Return resized buffer. 90 * @since 1.0 91 * @version 1.0 92 */ 93 BTSTACK_API Buffer *BufferResize(Buffer *buf, uint32_t offset, uint32_t size); 94 95 /** 96 * @brief Release Buffer. 97 * 98 * @param buf Buffer pointer. 99 * @since 1.0 100 * @version 1.0 101 */ 102 BTSTACK_API void BufferFree(Buffer *buf); 103 104 /** 105 * @brief Get Buffer data pointer. 106 * 107 * @param buf Buffer pointer. 108 * @return Buffer data pointer. 109 * @since 1.0 110 * @version 1.0 111 */ 112 BTSTACK_API void *BufferPtr(const Buffer *buf); 113 114 /** 115 * @brief Get Buffer size. 116 * 117 * @param buf Buffer pointer. 118 * @return Buffer size. 119 * @since 1.0 120 * @version 1.0 121 */ 122 BTSTACK_API uint32_t BufferGetSize(const Buffer *buf); 123 124 #ifdef __cplusplus 125 } 126 #endif 127 128 #endif // BUFFER_H