|
| 1 | +/* |
| 2 | + * Copyright (c) 2017, ARM Limited, All Rights Reserved |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | + * not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +/** |
| 18 | + * \file ac_buffer.h |
| 19 | + * \copyright Copyright (c) ARM Ltd 2013 |
| 20 | + * \author Donatien Garnier |
| 21 | + */ |
| 22 | + |
| 23 | +/** \addtogroup ACore |
| 24 | + * @{ |
| 25 | + * \name Buffer |
| 26 | + * @{ |
| 27 | + */ |
| 28 | + |
| 29 | +#ifndef ACORE_BUFFER_H_ |
| 30 | +#define ACORE_BUFFER_H_ |
| 31 | + |
| 32 | +#ifdef __cplusplus |
| 33 | +extern "C" { |
| 34 | +#endif |
| 35 | + |
| 36 | +#include "stdint.h" |
| 37 | +#include "stddef.h" |
| 38 | +#include "stdbool.h" |
| 39 | + |
| 40 | +typedef struct __ac_buffer { |
| 41 | + const uint8_t *data; |
| 42 | + size_t size; |
| 43 | + struct __ac_buffer *pNext; |
| 44 | +} ac_buffer_t; |
| 45 | + |
| 46 | +/** Initialize ac_buffer using underlying byte array, set ac_buffer's length to 0 (empty) |
| 47 | + * \param pBuf pointer to ac_buffer_t structure to initialize |
| 48 | + * \param data byte array to use |
| 49 | + * \param size size of byte array |
| 50 | + */ |
| 51 | +void ac_buffer_init(ac_buffer_t *pBuf, const uint8_t *data, size_t size); |
| 52 | + |
| 53 | +/** Copy pBufIn to pBuf |
| 54 | + * \param pBuf pointer to ac_buffer_t structure to initialize |
| 55 | + * \param pBufIn the source buffer |
| 56 | + */ |
| 57 | +void ac_buffer_dup(ac_buffer_t *pBuf, const ac_buffer_t *pBufIn); |
| 58 | + |
| 59 | +/** Get buffer's underlying byte array |
| 60 | + * \param pBuf pointer to ac_buffer_t structure |
| 61 | + * \return underlying array |
| 62 | + */ |
| 63 | +static inline const uint8_t *ac_buffer_data(const ac_buffer_t *pBuf) |
| 64 | +{ |
| 65 | + return pBuf->data; |
| 66 | +} |
| 67 | + |
| 68 | +/** Get buffer's size |
| 69 | + * \param pBuf pointer to ac_buffer_t structure |
| 70 | + * \return buffer's size |
| 71 | + */ |
| 72 | +static inline size_t ac_buffer_size(const ac_buffer_t *pBuf) |
| 73 | +{ |
| 74 | + return pBuf->size; |
| 75 | +} |
| 76 | + |
| 77 | +/** Get next buffer in chain |
| 78 | + * \param pBuf pointer to ac_buffer_t structure |
| 79 | + * \return pointer to next buffer |
| 80 | + */ |
| 81 | +static inline ac_buffer_t *ac_buffer_next(const ac_buffer_t *pBuf) |
| 82 | +{ |
| 83 | + return pBuf->pNext; |
| 84 | +} |
| 85 | + |
| 86 | +/** Set next buffer in chain |
| 87 | + * \param pBuf pointer to ac_buffer_t structure |
| 88 | + * \param pNextBuf pointer to next buffer (or NULL to break chain) |
| 89 | + */ |
| 90 | +static inline void ac_buffer_set_next(ac_buffer_t *pBuf, ac_buffer_t *pNextBuf) |
| 91 | +{ |
| 92 | + pBuf->pNext = (ac_buffer_t *) pNextBuf; |
| 93 | +} |
| 94 | + |
| 95 | +/** Append buffer to end of chain |
| 96 | + * \param pBuf pointer to ac_buffer_t structure |
| 97 | + * \param pAppBuf pointer to buffer to append to chain |
| 98 | + */ |
| 99 | +void ac_buffer_append(ac_buffer_t *pBuf, ac_buffer_t *pAppBuf); |
| 100 | + |
| 101 | +/** Truncate pBuf to length bytes and save the remaining bytes in pEndBuf |
| 102 | + * \param pBuf The buffer to split (will be set to invalid state) |
| 103 | + * \param pStartBuf A new buffer at the head of the split |
| 104 | + * \param pEndBuf A new buffer at the tail of the split |
| 105 | + * \param length How long pStartBuf should be (if longer than pBuf, then pStartBuf will be pBuf) |
| 106 | + */ |
| 107 | +void ac_buffer_split(ac_buffer_t *pStartBuf, ac_buffer_t *pEndBuf, ac_buffer_t *pBuf, size_t length); |
| 108 | + |
| 109 | +//Debug |
| 110 | +void ac_buffer_dump(ac_buffer_t *pBuf); |
| 111 | + |
| 112 | +#ifdef __cplusplus |
| 113 | +} |
| 114 | +#endif |
| 115 | + |
| 116 | +#endif /* ACORE_BUFFER_H_ */ |
| 117 | + |
| 118 | +/** |
| 119 | + * @} |
| 120 | + * @} |
| 121 | + * */ |
0 commit comments