1 /* 2 * Copyright (C) 2022-2023 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 #ifndef COMMON_BUFFER_H 17 #define COMMON_BUFFER_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 #include "defines.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 typedef struct { 28 uint8_t *buf; 29 uint32_t contentSize; 30 uint32_t maxSize; 31 } Buffer; 32 33 bool IsBufferValid(const Buffer *buffer); 34 Buffer GetTmpBuffer(uint8_t *buf, uint32_t contentSize, uint32_t maxSize); 35 Buffer *CreateBufferBySize(const uint32_t size); 36 void DestoryBuffer(Buffer *buffer); 37 Buffer *CopyBuffer(const Buffer *buffer); 38 bool CompareBuffer(const Buffer *buffer1, const Buffer *buffer2); 39 Buffer *CreateBufferByData(const uint8_t *data, const uint32_t dataSize); 40 ResultCode GetBufferData(const Buffer *buffer, uint8_t *data, uint32_t *dataSize); 41 bool CheckBufferWithSize(const Buffer *buffer, const uint32_t size); 42 43 #ifdef __cplusplus 44 } 45 #endif 46 47 #endif 48