Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
ByteBuffer.h
00001 /* 00002 * Copyright (c) 2018-2019, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may 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, 00013 * WITHOUT 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 #ifndef BYTE_BUFFER_H 00019 #define BYTE_BUFFER_H 00020 00021 #include <stdint.h> 00022 00023 /** 00024 * \defgroup drivers_ByteBuffer ByteBuffer class 00025 * \ingroup drivers-internal-api-usb 00026 * @{ 00027 */ 00028 class ByteBuffer { 00029 public: 00030 00031 /** 00032 * Create a byte buffer of the given size 00033 * 00034 * @param size Number of bytes this buffer can hold 00035 */ 00036 ByteBuffer(uint32_t size = 0); 00037 00038 /** 00039 * Delete this byte buffer 00040 */ 00041 ~ByteBuffer(); 00042 00043 /** 00044 * Set the size of the buffer 00045 * 00046 * Buffer contents are reset. 00047 * 00048 * @param size New buffer size 00049 */ 00050 void resize(uint32_t size); 00051 00052 /** 00053 * Add a single byte to this buffer 00054 * 00055 * There must be enough space in the buffer or the behavior is undefined. 00056 * 00057 * @param data byte to add 00058 */ 00059 void push(uint8_t data); 00060 00061 /** 00062 * Write a block of data to this ByteBuffer 00063 * 00064 * There must be enough space in the ByteBuffer or the behavior is undefined. 00065 * 00066 * @param data Block of data to write 00067 * @param size Size of data to write 00068 */ 00069 void write(uint8_t *data, uint32_t size); 00070 00071 /** 00072 * Remove a byte from this buffer 00073 * 00074 * @return data byte 00075 */ 00076 uint8_t pop(); 00077 00078 /** 00079 * Read a block of data from this ByteBuffer into a buffer pointed by 'data' 00080 * 00081 * There must be enough data in the ByteBuffer or the behavior is undefined. 00082 * 00083 * @param data Block of data to read 00084 * @param size Size of data to read 00085 */ 00086 void read(uint8_t *data, uint32_t size); 00087 00088 /** 00089 * Return the number bytes in this byte buffer 00090 * 00091 * @return Number of used bytes 00092 */ 00093 uint32_t size(); 00094 00095 /** 00096 * Return the number of additional bytes this buffer can hold 00097 * 00098 * @return Number of free bytes 00099 */ 00100 uint32_t free(); 00101 00102 /** 00103 * Check if this byte buffer is full 00104 * 00105 * @return true if full, false otherwise 00106 */ 00107 bool full(); 00108 00109 /** 00110 * Check if this byte buffer is empty 00111 * 00112 * @return true if empty, false otherwise 00113 */ 00114 bool empty(); 00115 00116 private: 00117 00118 uint32_t _head; 00119 uint32_t _tail; 00120 uint32_t _size; 00121 uint8_t *_buf; 00122 }; 00123 00124 /** @}*/ 00125 00126 #endif
Generated on Tue Jul 12 2022 13:54:04 by
