Syntax
[b,rbytes,err]=sbufferget(b,n)
Input Parameter
b : | | struct buffer |
n : | | number of bytes to get |
Output Parameter
b : | | updated buffer |
rbytes : | | array with received bytes |
err : | | error number |
Copyright 2015-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, sbufferget
, is designed to read a specified number of bytes from a buffer structure. It is part of a series of functions for managing a buffer, including creating, writing, and retrieving data.
Input Parameters
- b: A struct representing the buffer. It contains fields such as the buffer array, the current read position, and the total number of bytes available.
- n: The number of bytes to retrieve from the buffer.
Output Results
- b: The updated buffer struct after bytes have been read.
- rbytes: An array containing the bytes that were read from the buffer.
- err: A boolean indicating if an error occurred (true if the buffer contains fewer bytes than requested).
Algorithm Steps
- Retrieve buffer information using
sbufferinfo
, which provides the current state of the buffer.
- Initialize
err
as false
.
- Check if the buffer contains fewer bytes than requested (
n
). If so, issue a warning, set err
to true
, and exit the function.
- Calculate the indices of the bytes to be read using
mod1
, which handles circular buffer indexing.
- Extract the bytes from the buffer using the calculated indices and store them in
rbytes
.
- Optionally, overwrite the extracted bytes in the buffer with zeros for ASCII tests.
- Update the buffer's byte count (
b.anz
) by subtracting the number of bytes read.
- Update the buffer's read position (
b.r
) to the last index of the read bytes.
Algorithm explaination created using ChatGPT on 2025-08-18 23:31. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21