input_from_buffer.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  *   Copyright (C) 2013-2014 by Alexander Rykovanov                        *
00003  *   rykovanov.as@gmail.com                                                   *
00004  *                                                                            *
00005  *   This library is free software; you can redistribute it and/or modify     *
00006  *   it under the terms of the GNU Lesser General Public License as           *
00007  *   published by the Free Software Foundation; version 3 of the License.     *
00008  *                                                                            *
00009  *   This library is distributed in the hope that it will be useful,          *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00012  *   GNU Lesser General Public License for more details.                      *
00013  *                                                                            *
00014  *   You should have received a copy of the GNU Lesser General Public License *
00015  *   along with this library; if not, write to the                            *
00016  *   Free Software Foundation, Inc.,                                          *
00017  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                *
00018  ******************************************************************************/
00019 
00020 #include <opc/ua/protocol/input_from_buffer.h>
00021 
00022 #include <stdexcept>
00023 #include <cstring>
00024 #include <algorithm>
00025 
00026 namespace OpcUa
00027 {
00028 
00029   InputFromBuffer::InputFromBuffer(const char* buf, std::size_t bufSize)
00030     : Buffer(buf)
00031     , Size(bufSize)
00032   {
00033     if (!Buffer) throw std::invalid_argument("InputFromBuffer: Input buffer cannot be empty.");
00034     if (!bufSize) throw std::invalid_argument("InputFromBuffer: Invalid size of buffer");
00035   }
00036 
00037   std::size_t InputFromBuffer::Receive(char* data, std::size_t size)
00038   {
00039     if (Size == 0)
00040     {
00041       return 0;
00042     }
00043 
00044     const std::size_t sizeToRead = std::min(Size, size);
00045     memcpy(data, Buffer, sizeToRead);
00046     Size -= sizeToRead;
00047     Buffer += sizeToRead;
00048     return sizeToRead;
00049   }
00050 
00051   size_t InputFromBuffer::GetRemainSize() const
00052   {
00053     return Size;
00054   }
00055 
00056 }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:56