Mbed OS Reference
Loading...
Searching...
No Matches
ac_buffer.h
Go to the documentation of this file.
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/** \defgroup ACore ACore
24 * \ingroup nfc
25 * @{
26 * \name Buffer
27 * @{
28 */
29
30#ifndef ACORE_BUFFER_H_
31#define ACORE_BUFFER_H_
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#include "stdint.h"
38#include "stddef.h"
39#include "stdbool.h"
40
41typedef struct __ac_buffer {
42 const uint8_t *data;
43 size_t size;
44 struct __ac_buffer *pNext;
46
47/** Initialize ac_buffer using underlying byte array, set ac_buffer's length to 0 (empty)
48 * \param pBuf pointer to ac_buffer_t structure to initialize
49 * \param data byte array to use
50 * \param size size of byte array
51 */
52void ac_buffer_init(ac_buffer_t *pBuf, const uint8_t *data, size_t size);
53
54/** Copy pBufIn to pBuf
55 * \param pBuf pointer to ac_buffer_t structure to initialize
56 * \param pBufIn the source buffer
57 */
58void ac_buffer_dup(ac_buffer_t *pBuf, const ac_buffer_t *pBufIn);
59
60/** Get buffer's underlying byte array
61 * \param pBuf pointer to ac_buffer_t structure
62 * \return underlying array
63 */
64static inline const uint8_t *ac_buffer_data(const ac_buffer_t *pBuf)
65{
66 return pBuf->data;
67}
68
69/** Get buffer's size
70 * \param pBuf pointer to ac_buffer_t structure
71 * \return buffer's size
72 */
73static inline size_t ac_buffer_size(const ac_buffer_t *pBuf)
74{
75 return pBuf->size;
76}
77
78/** Get next buffer in chain
79 * \param pBuf pointer to ac_buffer_t structure
80 * \return pointer to next buffer
81 */
82static inline ac_buffer_t *ac_buffer_next(const ac_buffer_t *pBuf)
83{
84 return pBuf->pNext;
85}
86
87/** Set next buffer in chain
88 * \param pBuf pointer to ac_buffer_t structure
89 * \param pNextBuf pointer to next buffer (or NULL to break chain)
90 */
91static inline void ac_buffer_set_next(ac_buffer_t *pBuf, ac_buffer_t *pNextBuf)
92{
93 pBuf->pNext = (ac_buffer_t *) pNextBuf;
94}
95
96/** Append buffer to end of chain
97 * \param pBuf pointer to ac_buffer_t structure
98 * \param pAppBuf pointer to buffer to append to chain
99 */
101
102/** Truncate pBuf to length bytes and save the remaining bytes in pEndBuf
103 * \param pBuf The buffer to split (will be set to invalid state)
104 * \param pStartBuf A new buffer at the head of the split
105 * \param pEndBuf A new buffer at the tail of the split
106 * \param length How long pStartBuf should be (if longer than pBuf, then pStartBuf will be pBuf)
107 */
108void ac_buffer_split(ac_buffer_t *pStartBuf, ac_buffer_t *pEndBuf, ac_buffer_t *pBuf, size_t length);
109
110//Debug
111void ac_buffer_dump(ac_buffer_t *pBuf);
112
113#ifdef __cplusplus
114}
115#endif
116
117#endif /* ACORE_BUFFER_H_ */
118
119/**
120 * @}
121 * @}
122 * */
void ac_buffer_split(ac_buffer_t *pStartBuf, ac_buffer_t *pEndBuf, ac_buffer_t *pBuf, size_t length)
Truncate pBuf to length bytes and save the remaining bytes in pEndBuf.
void ac_buffer_append(ac_buffer_t *pBuf, ac_buffer_t *pAppBuf)
Append buffer to end of chain.
void ac_buffer_dup(ac_buffer_t *pBuf, const ac_buffer_t *pBufIn)
Copy pBufIn to pBuf.
void ac_buffer_init(ac_buffer_t *pBuf, const uint8_t *data, size_t size)
Initialize ac_buffer using underlying byte array, set ac_buffer's length to 0 (empty)