SerUt  1.1.1 (development version)
vectorserializer.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of SerUt, a library containing some serialization
4  utilities.
5 
6  Copyright (C) 2008-2018 Jori Liesenborgs
7 
8  Contact: jori.liesenborgs@gmail.com
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23  USA
24 
25 */
26 
31 #ifndef SERUT_VECTORSERIALIZER_H
32 
33 #define SERUT_VECTORSERIALIZER_H
34 
35 #include "serutconfig.h"
36 #include "serializationinterface.h"
37 #include <stdint.h>
38 
39 namespace serut
40 {
41 
43 class SERUT_IMPORTEXPORT VectorSerializer : public SerializationInterface
44 {
45 public:
50  VectorSerializer(const std::vector<uint8_t> &initialBuffer);
52 
53  bool readBytes(void *pBuffer, size_t amount);
54  bool writeBytes(const void *pBuffer, size_t amount);
55 
57  const std::vector<uint8_t> &getBuffer() const { return m_bytes; }
58 
60  const unsigned char *getBufferPointer() { return static_cast<const unsigned char *>(&m_bytes[0]); }
61 
63  int getBufferSize() const { return m_bytes.size(); }
64 private:
65  int m_readPos;
66  std::vector<uint8_t> m_bytes;
67 };
68 
69 } // end namespace
70 
71 #endif // SERUT_VECTORSERIALIZER_H
Generic serialization interface.
Definition: serializationinterface.h:58
A serializer which uses an STL vector, which can grow in size.
Definition: vectorserializer.h:44
const std::vector< uint8_t > & getBuffer() const
Returns the vector instance that's being used for reading and writing.
Definition: vectorserializer.h:57
const unsigned char * getBufferPointer()
Returns a pointer to the first element of the internal buffer (do not use if no data is available!...
Definition: vectorserializer.h:60
VectorSerializer()
Construct an instance with no predefined data - what you read is only what you've written.
VectorSerializer(const std::vector< uint8_t > &initialBuffer)
Construct an instance which will copy the specified initial data - new writes will append,...
int getBufferSize() const
Returns the current size of the internal buffer.
Definition: vectorserializer.h:63