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