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
24extern "C" {
25#endif
26
27typedef struct {
28    uint8_t *buf;
29    uint32_t contentSize;
30    uint32_t maxSize;
31} Buffer;
32
33bool IsBufferValid(const Buffer *buffer);
34Buffer GetTmpBuffer(uint8_t *buf, uint32_t contentSize, uint32_t maxSize);
35Buffer *CreateBufferBySize(const uint32_t size);
36void DestoryBuffer(Buffer *buffer);
37Buffer *CopyBuffer(const Buffer *buffer);
38bool CompareBuffer(const Buffer *buffer1, const Buffer *buffer2);
39Buffer *CreateBufferByData(const uint8_t *data, const uint32_t dataSize);
40ResultCode GetBufferData(const Buffer *buffer, uint8_t *data, uint32_t *dataSize);
41bool CheckBufferWithSize(const Buffer *buffer, const uint32_t size);
42Buffer *MergeBuffers(const Buffer *buffer1, const Buffer *buffer2);
43
44#ifdef __cplusplus
45}
46#endif
47
48#endif
49