SerUt  1.1.1 (development version)
memoryserializer.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_MEMORYSERIALIZER_H
32 
33 #define SERUT_MEMORYSERIALIZER_H
34 
35 #include "serutconfig.h"
36 #include "serializationinterface.h"
37 
38 namespace serut
39 {
40 
42 class SERUT_IMPORTEXPORT MemorySerializer : public SerializationInterface
43 {
44 public:
52  MemorySerializer(const void *pReadBuffer, size_t readSize,
53  void *pWriteBuffer, size_t writeSize);
54 
56 
58  size_t getBytesRead() const { return m_readPosition; }
59 
61  size_t getBytesWritten() const { return m_writePosition; }
62 
63  bool readBytes(void *pBuffer, size_t amount);
64  bool writeBytes(const void *pBuffer, size_t amount);
65 private:
66  const uint8_t *m_pReadBuffer;
67  uint8_t *m_pWriteBuffer;
68  size_t m_readPosition;
69  size_t m_writePosition;
70  size_t m_readSize;
71  size_t m_writeSize;
72 };
73 
74 } // end namespace
75 
76 #endif // SERUT_MEMORYSERIALIZER_H
77 
A serializer for reading from and writing to memory.
Definition: memoryserializer.h:43
size_t getBytesRead() const
Returns the amount of bytes that have currently been read.
Definition: memoryserializer.h:58
size_t getBytesWritten() const
Returns the amount of bytes that have currently been written.
Definition: memoryserializer.h:61
MemorySerializer(const void *pReadBuffer, size_t readSize, void *pWriteBuffer, size_t writeSize)
Construct an instance.
Generic serialization interface.
Definition: serializationinterface.h:58