embkernel
 All Classes Functions Variables Typedefs Groups Pages
LibStreamInArray.cpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #include "LibStreamInArray.hpp"
7 #include <string.h>
8 
9 LibStreamInArray::LibStreamInArray(uint8_t* buffer, int size) {
10  mBuffer = buffer;
11  mBufferSize = size;
12  mPosition = 0;
13 }
14 
15 int LibStreamInArray::read(void* buffer, int len, Rtos::TICK timeout) {
16  int left = mBufferSize - mPosition;
17  if (left <= 0) {
18  return 0;
19  }
20  if (len > left) {
21  len = left;
22  }
23  memcpy(buffer, &mBuffer[mPosition], len);
24 
25  mPosition += len;
26  return len;
27 }
28