takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ac_buffer_reader.h Source File

ac_buffer_reader.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2017, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 /**
00018  * \file ac_buffer_reader.h
00019  * \copyright Copyright (c) ARM Ltd 2015
00020  * \author Donatien Garnier
00021  */
00022 
00023 /** \addtogroup ACore
00024  *  @{
00025  *  \name Buffer Reader
00026  *  @{
00027  */
00028 
00029 #ifndef ACORE_BUFFER_READER_H_
00030 #define ACORE_BUFFER_READER_H_
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 #include "stdint.h"
00037 #include "stddef.h"
00038 #include "stdbool.h"
00039 
00040 #include "acore/ac_buffer.h"
00041 
00042 /** Read n-bytes in big-endian format from buffer reader and advance read posiion
00043  * \param pBuf the buffer to read from
00044  * \param buf the array to write to
00045  * \param size the number of bytes to read
00046  */
00047 void ac_buffer_read_be(ac_buffer_t *pBuf, uint8_t *buf, size_t size);
00048 
00049 /** Read n-bytes in little-endian format from buffer reader and advance read posiion
00050  * \param pBuf the buffer to read from
00051  * \param buf the array to write to
00052  * \param size the number of bytes to read
00053  */
00054 void ac_buffer_read_le(ac_buffer_t *pBuf, uint8_t *buf, size_t size);
00055 
00056 /** Read 8-bit value from buffer reader and advance read posiion
00057  * \param pBuf the buffer to read from
00058  * \return 8-bit value read
00059  */
00060 static inline uint8_t ac_buffer_read_nu8(ac_buffer_t *pBuf)
00061 {
00062     uint8_t hu8;
00063     ac_buffer_read_be(pBuf, &hu8, 1);
00064     return hu8;
00065 }
00066 
00067 /** Read BE 16-bit value from buffer reader and advance read posiion
00068  * \param pBuf the buffer to read from
00069  * \return 16-bit value read
00070  */
00071 static inline uint16_t ac_buffer_read_nu16(ac_buffer_t *pBuf)
00072 {
00073     uint16_t hu16;
00074     ac_buffer_read_be(pBuf, (uint8_t *)&hu16, 2);
00075     return hu16;
00076 }
00077 
00078 /** Read BE 24-bit value from buffer reader and advance read posiion
00079  * \param pBuf the buffer to read from
00080  * \return 24-bit value read
00081  */
00082 static inline uint32_t ac_buffer_read_nu24(ac_buffer_t *pBuf)
00083 {
00084     uint32_t hu24;
00085     ac_buffer_read_be(pBuf, (uint8_t *)&hu24, 3);
00086     return hu24;
00087 }
00088 
00089 /** Read BE 32-bit value from buffer reader and advance read posiion
00090  * \param pBuf the buffer to read from
00091  * \return 32-bit value read
00092  */
00093 static inline uint32_t ac_buffer_read_nu32(ac_buffer_t *pBuf)
00094 {
00095     uint32_t hu32;
00096     ac_buffer_read_be(pBuf, (uint8_t *)&hu32, 4);
00097     return hu32;
00098 }
00099 
00100 /** Read BE 64-bit value from buffer reader and advance read posiion
00101  * \param pBuf the buffer to read from
00102  * \return 64-bit value read
00103  */
00104 static inline uint64_t ac_buffer_read_nu64(ac_buffer_t *pBuf)
00105 {
00106     uint64_t hu64;
00107     ac_buffer_read_be(pBuf, (uint8_t *)&hu64, 8);
00108     return hu64;
00109 }
00110 
00111 /** Read n bytes from buffer reader and advance read posiion
00112  * \param pBuf the buffer to read from
00113  * \param data the array to write bytes to
00114  * \param size the number of bytes to read
00115  */
00116 static inline void ac_buffer_read_n_bytes(ac_buffer_t *pBuf, uint8_t *data, size_t size)
00117 {
00118     ac_buffer_read_le(pBuf, data, size);
00119 }
00120 
00121 /** Skip n bytes from buffer reader and advance read posiion
00122  * \param pBuf the buffer to read from
00123  * \param size the number of bytes to skip
00124  */
00125 void ac_buffer_read_n_skip(ac_buffer_t *pBuf, size_t size);
00126 
00127 /** Get number of bytes readable from buffer
00128  * \param pBuf the buffer to read from
00129  * \return The number of bytes which can be read
00130  */
00131 size_t ac_buffer_reader_readable(const ac_buffer_t *pBuf);
00132 
00133 /** Get a pointer to the current position within this buffer's current backing array
00134  * \param pBuf the buffer to read from
00135  * \return A pointer to the current position within the current backing array
00136  */
00137 const uint8_t *ac_buffer_reader_current_buffer_pointer(ac_buffer_t *pBuf);
00138 
00139 /** Get the number of bytes readable within the current backing array
00140  * \param pBuf the buffer to read from
00141  * \return The number of bytes readable within the current backing array
00142  */
00143 size_t ac_buffer_reader_current_buffer_length(ac_buffer_t *pBuf);
00144 
00145 /** Compare buffer with array (does not advance read position)
00146  * \param pBuf the buffer to compare from
00147  * \param bytes the array to compare with
00148  * \param length the array length
00149  * \return Whether the buffer is AT LEAST as long as the array AND the buffer and array have the same content
00150  */
00151 bool ac_buffer_reader_cmp_bytes(const ac_buffer_t *pBuf, const uint8_t *bytes, size_t length);
00152 
00153 /** Compare buffer with array (does not advance read position)
00154  * \param pBuf1 the buffer to compare from
00155  * \param pBuf2 the buffer to compare with
00156  * \return Whether the buffers have the same length and content
00157  */
00158 bool ac_buffer_reader_cmp(const ac_buffer_t *pBuf1, const ac_buffer_t *pBuf2);
00159 
00160 #ifdef __cplusplus
00161 }
00162 #endif
00163 
00164 #endif /* CORE_ac_buffer_READER_H_ */
00165 
00166 /**
00167  * @}
00168  * @}
00169  * */