input_from_buffer.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2013-2014 by Alexander Rykovanov *
3  * rykovanov.as@gmail.com *
4  * *
5  * This library is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU Lesser General Public License as *
7  * published by the Free Software Foundation; version 3 of the License. *
8  * *
9  * This library is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU Lesser General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Lesser General Public License *
15  * along with this library; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18  ******************************************************************************/
19 
21 
22 #include <stdexcept>
23 #include <cstring>
24 #include <algorithm>
25 
26 namespace OpcUa
27 {
28 
29 InputFromBuffer::InputFromBuffer(const char * buf, std::size_t bufSize)
30  : Buffer(buf)
31  , Size(bufSize)
32 {
33  if (!Buffer) { throw std::invalid_argument("InputFromBuffer: Input buffer cannot be empty."); }
34 
35  if (!bufSize) { throw std::invalid_argument("InputFromBuffer: Invalid size of buffer"); }
36 }
37 
38 std::size_t InputFromBuffer::Receive(char * data, std::size_t size)
39 {
40  if (Size == 0)
41  {
42  return 0;
43  }
44 
45  const std::size_t sizeToRead = std::min(Size, size);
46  memcpy(data, Buffer, sizeToRead);
47  Size -= sizeToRead;
48  Buffer += sizeToRead;
49  return sizeToRead;
50 }
51 
53 {
54  return Size;
55 }
56 
57 }
InputFromBuffer(const char *buf, std::size_t bufSize)
size_t GetRemainSize() const
virtual std::size_t Receive(char *data, std::size_t size) override
Receive data.
OPC UA Address space part. GNU LGPL.


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:06