• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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
26 extern "C" {
27 #endif // __cplusplus
28 
29 typedef struct {
30     uint8_t *buf;
31     uint32_t contentSize;
32     uint32_t maxSize;
33 } Buffer;
34 
35 bool IsBufferValid(const Buffer *buffer);
36 Buffer *CreateBufferBySize(const uint32_t size);
37 ResultCode InitBuffer(Buffer *buffer, const uint8_t *buf, const uint32_t bufSize);
38 void DestoryBuffer(Buffer *buffer);
39 Buffer *CopyBuffer(const Buffer *buffer);
40 bool CompareBuffer(const Buffer *buffer1, const Buffer *buffer2);
41 Buffer *CreateBufferByData(const uint8_t *data, const uint32_t dataSize);
42 ResultCode GetBufferData(const Buffer *buffer, uint8_t *data, uint32_t *dataSize);
43 bool CheckBufferWithSize(const Buffer *buffer, const uint32_t size);
44 
45 #ifdef __cplusplus
46 }
47 #endif // __cplusplus
48 #endif // COMMON_BUFFER_H