Revision | 78e54ff3437b86dd432f10cda34a481e95961d22 (tree) |
---|---|
Zeit | 2014-05-19 05:10:30 |
Autor | wbenny <w.benny@outl...> |
Commiter | wbenny |
* Remove dependency on char_type in non-stream classes and use uint8_t instead.
* Move serialize/deserialize functions into utils::stream namespace.
@@ -114,7 +114,7 @@ TEST_METHOD(Sample_ZipArchive_Stream_Deferred_Comment) | ||
114 | 114 | //// this method is only useful for password protected files |
115 | 115 | //entry->UseDataDescriptor(); |
116 | 116 | |
117 | - StoreMethod::Ptr ctx = StoreMethod::Create(); | |
117 | + LzmaMethod::Ptr ctx = LzmaMethod::Create(); | |
118 | 118 | AesCryptoMethod::Ptr encryptionCtx = AesCryptoMethod::Create(); |
119 | 119 | encryptionCtx->SetPassword("gogo"); |
120 | 120 | ctx->SetEncryptionMethod(encryptionCtx); |
@@ -94,7 +94,7 @@ | ||
94 | 94 | <Optimization>Disabled</Optimization> |
95 | 95 | <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
96 | 96 | <DisableSpecificWarnings>4250;4996</DisableSpecificWarnings> |
97 | - <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> | |
97 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
98 | 98 | </ClCompile> |
99 | 99 | <Link> |
100 | 100 | <SubSystem>Console</SubSystem> |
@@ -110,6 +110,7 @@ | ||
110 | 110 | <Optimization>Disabled</Optimization> |
111 | 111 | <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
112 | 112 | <DisableSpecificWarnings>4250;4996</DisableSpecificWarnings> |
113 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
113 | 114 | </ClCompile> |
114 | 115 | <Link> |
115 | 116 | <SubSystem>Console</SubSystem> |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #include "ZipArchive.h" |
2 | -#include "streams/serialization.h" | |
2 | +#include "utils/stream/serialization.h" | |
3 | 3 | |
4 | 4 | #include <algorithm> |
5 | 5 | #include <cassert> |
@@ -197,7 +197,7 @@ bool ZipArchive::SeekToSignature(uint32_t signature, SeekDirection direction) | ||
197 | 197 | |
198 | 198 | while (!_zipStream->eof() && !_zipStream->fail()) |
199 | 199 | { |
200 | - deserialize(*_zipStream, buffer); | |
200 | + utils::stream::deserialize(*_zipStream, buffer); | |
201 | 201 | |
202 | 202 | if (buffer == signature) |
203 | 203 | { |
@@ -79,7 +79,6 @@ | ||
79 | 79 | <ClInclude Include="streams\encryption_encoder_stream.h" /> |
80 | 80 | <ClInclude Include="streams\memstream.h" /> |
81 | 81 | <ClInclude Include="streams\nullstream.h" /> |
82 | - <ClInclude Include="streams\serialization.h" /> | |
83 | 82 | <ClInclude Include="streams\streambuffs\audit_streambuf.h" /> |
84 | 83 | <ClInclude Include="streams\streambuffs\compression_decoder_streambuf.h" /> |
85 | 84 | <ClInclude Include="streams\streambuffs\compression_encoder_streambuf.h" /> |
@@ -93,6 +92,8 @@ | ||
93 | 92 | <ClInclude Include="streams\substream.h" /> |
94 | 93 | <ClInclude Include="streams\teestream.h" /> |
95 | 94 | <ClInclude Include="utils\enum_utils.h" /> |
95 | + <ClInclude Include="utils\stream\copy.h" /> | |
96 | + <ClInclude Include="utils\stream\serialization.h" /> | |
96 | 97 | <ClInclude Include="utils\stream_utils.h" /> |
97 | 98 | <ClInclude Include="utils\time_utils.h" /> |
98 | 99 | <ClInclude Include="ZipArchive.h" /> |
@@ -197,6 +198,7 @@ | ||
197 | 198 | <Optimization>Disabled</Optimization> |
198 | 199 | <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
199 | 200 | <DisableSpecificWarnings>4996</DisableSpecificWarnings> |
201 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
200 | 202 | </ClCompile> |
201 | 203 | <Link> |
202 | 204 | <SubSystem>Windows</SubSystem> |
@@ -211,6 +213,7 @@ | ||
211 | 213 | <Optimization>Disabled</Optimization> |
212 | 214 | <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
213 | 215 | <DisableSpecificWarnings>4996</DisableSpecificWarnings> |
216 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
214 | 217 | </ClCompile> |
215 | 218 | <Link> |
216 | 219 | <SubSystem>Windows</SubSystem> |
@@ -85,6 +85,9 @@ | ||
85 | 85 | <Filter Include="Header Files\methods\encryption\detail"> |
86 | 86 | <UniqueIdentifier>{fdd8531d-8da9-439a-bde5-24b55515a5c9}</UniqueIdentifier> |
87 | 87 | </Filter> |
88 | + <Filter Include="Header Files\utils\stream"> | |
89 | + <UniqueIdentifier>{7aa687c2-d8de-4cdb-a3fb-20076486838b}</UniqueIdentifier> | |
90 | + </Filter> | |
88 | 91 | </ItemGroup> |
89 | 92 | <ItemGroup> |
90 | 93 | <ClInclude Include="ZipFile.h"> |
@@ -135,9 +138,6 @@ | ||
135 | 138 | <ClInclude Include="streams\memstream.h"> |
136 | 139 | <Filter>Header Files\streams</Filter> |
137 | 140 | </ClInclude> |
138 | - <ClInclude Include="streams\serialization.h"> | |
139 | - <Filter>Header Files\streams</Filter> | |
140 | - </ClInclude> | |
141 | 141 | <ClInclude Include="streams\substream.h"> |
142 | 142 | <Filter>Header Files\streams</Filter> |
143 | 143 | </ClInclude> |
@@ -324,6 +324,12 @@ | ||
324 | 324 | <ClInclude Include="compression\bzip2\bzip2_properties.h"> |
325 | 325 | <Filter>Header Files\compression\bzip2</Filter> |
326 | 326 | </ClInclude> |
327 | + <ClInclude Include="utils\stream\copy.h"> | |
328 | + <Filter>Header Files\utils\stream</Filter> | |
329 | + </ClInclude> | |
330 | + <ClInclude Include="utils\stream\serialization.h"> | |
331 | + <Filter>Header Files\utils\stream</Filter> | |
332 | + </ClInclude> | |
327 | 333 | </ItemGroup> |
328 | 334 | <ItemGroup> |
329 | 335 | <ClCompile Include="ZipFile.cpp"> |
@@ -1,8 +1,7 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../compression_interface.h" | |
3 | - | |
4 | 2 | #include "bzip2_properties.h" |
5 | - | |
3 | +#include "../compression_interface.h" | |
4 | +#include "../../utils/stream/serialization.h" | |
6 | 5 | #include "../../extlibs/bzip2/bzlib.h" |
7 | 6 | |
8 | 7 | #include <cstdint> |
@@ -45,17 +44,17 @@ class bzip2_decoder | ||
45 | 44 | _bufferCapacity = bzip2Props.BufferCapacity; |
46 | 45 | |
47 | 46 | uninit_buffers(); |
48 | - _inputBuffer = new char_type[_bufferCapacity]; | |
49 | - _outputBuffer = new char_type[_bufferCapacity]; | |
47 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
48 | + _outputBuffer = new uint8_t[_bufferCapacity]; | |
50 | 49 | |
51 | 50 | // init bzip2 |
52 | - _bzstream.bzalloc = nullptr; | |
53 | - _bzstream.bzfree = nullptr; | |
54 | - _bzstream.opaque = nullptr; | |
51 | + _bzstream.bzalloc = nullptr; | |
52 | + _bzstream.bzfree = nullptr; | |
53 | + _bzstream.opaque = nullptr; | |
55 | 54 | |
56 | - _bzstream.next_in = nullptr; | |
57 | - _bzstream.next_out = nullptr; | |
58 | - _bzstream.avail_in = 0; | |
55 | + _bzstream.next_in = nullptr; | |
56 | + _bzstream.next_out = nullptr; | |
57 | + _bzstream.avail_in = 0; | |
59 | 58 | _bzstream.avail_out = (unsigned int)-1; // force first load of data |
60 | 59 | |
61 | 60 | // no verbosity & do not use small memory model |
@@ -67,12 +66,12 @@ class bzip2_decoder | ||
67 | 66 | return (_inputBuffer != nullptr && _outputBuffer != nullptr); |
68 | 67 | } |
69 | 68 | |
70 | - char_type* get_buffer_begin() override | |
69 | + uint8_t* get_buffer_begin() override | |
71 | 70 | { |
72 | 71 | return _outputBuffer; |
73 | 72 | } |
74 | 73 | |
75 | - char_type* get_buffer_end() override | |
74 | + uint8_t* get_buffer_end() override | |
76 | 75 | { |
77 | 76 | return _outputBuffer + _outputBufferSize; |
78 | 77 | } |
@@ -139,7 +138,7 @@ class bzip2_decoder | ||
139 | 138 | void read_next() |
140 | 139 | { |
141 | 140 | // read next bytes from input stream |
142 | - _stream->read(_inputBuffer, _bufferCapacity); | |
141 | + utils::stream::deserialize(*_stream, _inputBuffer, _bufferCapacity); | |
143 | 142 | |
144 | 143 | // set the size of buffer |
145 | 144 | _inputBufferSize = static_cast<size_t>(_stream->gcount()); |
@@ -162,6 +161,6 @@ class bzip2_decoder | ||
162 | 161 | size_t _bufferCapacity = 0; |
163 | 162 | size_t _inputBufferSize = 0; // how many bytes are read in the input buffer |
164 | 163 | size_t _outputBufferSize = 0; // how many bytes are written in the output buffer |
165 | - char_type* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
166 | - char_type* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
164 | + uint8_t* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
165 | + uint8_t* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
167 | 166 | }; |
@@ -1,8 +1,7 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../compression_interface.h" | |
3 | - | |
4 | 2 | #include "bzip2_properties.h" |
5 | - | |
3 | +#include "../compression_interface.h" | |
4 | +#include "../../utils/stream/serialization.h" | |
6 | 5 | #include "../../extlibs/bzip2/bzlib.h" |
7 | 6 | |
8 | 7 | #include <cstdint> |
@@ -41,17 +40,17 @@ class bzip2_encoder | ||
41 | 40 | _bufferCapacity = bz2Props.BufferCapacity; |
42 | 41 | |
43 | 42 | uninit_buffers(); |
44 | - _inputBuffer = new char_type[_bufferCapacity]; | |
45 | - _outputBuffer = new char_type[_bufferCapacity]; | |
43 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
44 | + _outputBuffer = new uint8_t[_bufferCapacity]; | |
46 | 45 | |
47 | 46 | // init bzip2 |
48 | - _bzstream.bzalloc = nullptr; | |
49 | - _bzstream.bzfree = nullptr; | |
50 | - _bzstream.opaque = nullptr; | |
47 | + _bzstream.bzalloc = nullptr; | |
48 | + _bzstream.bzfree = nullptr; | |
49 | + _bzstream.opaque = nullptr; | |
51 | 50 | |
52 | - _bzstream.next_in = nullptr; | |
53 | - _bzstream.next_out = nullptr; | |
54 | - _bzstream.avail_in = 0; | |
51 | + _bzstream.next_in = nullptr; | |
52 | + _bzstream.next_out = nullptr; | |
53 | + _bzstream.avail_in = 0; | |
55 | 54 | _bzstream.avail_out = 0; |
56 | 55 | |
57 | 56 | _lastError = BZ2_bzCompressInit(&_bzstream, bz2Props.BlockSize, 0, bz2Props.WorkFactor); |
@@ -62,12 +61,12 @@ class bzip2_encoder | ||
62 | 61 | return _stream != nullptr; |
63 | 62 | } |
64 | 63 | |
65 | - char_type* get_buffer_begin() override | |
64 | + uint8_t* get_buffer_begin() override | |
66 | 65 | { |
67 | 66 | return _inputBuffer; |
68 | 67 | } |
69 | 68 | |
70 | - char_type* get_buffer_end() override | |
69 | + uint8_t* get_buffer_end() override | |
71 | 70 | { |
72 | 71 | return _inputBuffer + _bufferCapacity; |
73 | 72 | } |
@@ -93,7 +92,7 @@ class bzip2_encoder | ||
93 | 92 | |
94 | 93 | if (have > 0) |
95 | 94 | { |
96 | - _stream->write(_outputBuffer, have); | |
95 | + utils::stream::serialize(*_stream, _outputBuffer, have); | |
97 | 96 | } |
98 | 97 | } while (_bzstream.avail_out == 0); |
99 | 98 | } |
@@ -121,6 +120,6 @@ class bzip2_encoder | ||
121 | 120 | std::ostream* _stream = nullptr; |
122 | 121 | |
123 | 122 | size_t _bufferCapacity = 0; |
124 | - char_type* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
125 | - char_type* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
123 | + uint8_t* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
124 | + uint8_t* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
126 | 125 | }; |
@@ -19,14 +19,12 @@ struct compression_properties_interface | ||
19 | 19 | class compression_interface |
20 | 20 | { |
21 | 21 | public: |
22 | - typedef char char_type; | |
23 | - | |
24 | 22 | virtual ~compression_interface() { } |
25 | 23 | |
26 | 24 | virtual bool is_init() const = 0; |
27 | 25 | |
28 | - virtual char_type* get_buffer_begin() = 0; | |
29 | - virtual char_type* get_buffer_end() = 0; | |
26 | + virtual uint8_t* get_buffer_begin() = 0; | |
27 | + virtual uint8_t* get_buffer_end() = 0; | |
30 | 28 | }; |
31 | 29 | |
32 | 30 | class compression_encoder_interface |
@@ -1,9 +1,8 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../compression_interface.h" | |
3 | - | |
4 | 2 | #include "deflate_properties.h" |
5 | - | |
6 | -#include "../../extlibs/zlib/zlib.h" | |
3 | +#include "../compression_interface.h" | |
4 | +#include "../../utils/stream/serialization.h" | |
5 | +#include "../../extlibs/zlib/zlib.h" | |
7 | 6 | |
8 | 7 | #include <cstdint> |
9 | 8 |
@@ -45,18 +44,18 @@ class deflate_decoder | ||
45 | 44 | _bufferCapacity = deflateProps.BufferCapacity; |
46 | 45 | |
47 | 46 | uninit_buffers(); |
48 | - _inputBuffer = new char_type[_bufferCapacity]; | |
49 | - _outputBuffer = new char_type[_bufferCapacity]; | |
47 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
48 | + _outputBuffer = new uint8_t[_bufferCapacity]; | |
50 | 49 | |
51 | 50 | // init deflate |
52 | - _zstream.zalloc = nullptr; | |
53 | - _zstream.zfree = nullptr; | |
54 | - _zstream.opaque = nullptr; | |
51 | + _zstream.zalloc = nullptr; | |
52 | + _zstream.zfree = nullptr; | |
53 | + _zstream.opaque = nullptr; | |
55 | 54 | |
56 | - _zstream.next_in = nullptr; | |
57 | - _zstream.next_out = nullptr; | |
58 | - _zstream.avail_in = 0; | |
59 | - _zstream.avail_out = uInt(-1); // force first load of data | |
55 | + _zstream.next_in = nullptr; | |
56 | + _zstream.next_out = nullptr; | |
57 | + _zstream.avail_in = 0; | |
58 | + _zstream.avail_out = uInt(-1); // force first load of data | |
60 | 59 | |
61 | 60 | inflateInit2(&_zstream, -MAX_WBITS); |
62 | 61 | } |
@@ -66,12 +65,12 @@ class deflate_decoder | ||
66 | 65 | return (_inputBuffer != nullptr && _outputBuffer != nullptr); |
67 | 66 | } |
68 | 67 | |
69 | - char_type* get_buffer_begin() override | |
68 | + uint8_t* get_buffer_begin() override | |
70 | 69 | { |
71 | 70 | return _outputBuffer; |
72 | 71 | } |
73 | 72 | |
74 | - char_type* get_buffer_end() override | |
73 | + uint8_t* get_buffer_end() override | |
75 | 74 | { |
76 | 75 | return _outputBuffer + _outputBufferSize; |
77 | 76 | } |
@@ -138,7 +137,7 @@ class deflate_decoder | ||
138 | 137 | void read_next() |
139 | 138 | { |
140 | 139 | // read next bytes from input stream |
141 | - _stream->read(_inputBuffer, _bufferCapacity); | |
140 | + utils::stream::deserialize(*_stream, _inputBuffer, _bufferCapacity); | |
142 | 141 | |
143 | 142 | // set the size of buffer |
144 | 143 | _inputBufferSize = static_cast<size_t>(_stream->gcount()); |
@@ -161,6 +160,6 @@ class deflate_decoder | ||
161 | 160 | size_t _bufferCapacity = 0; |
162 | 161 | size_t _inputBufferSize = 0; // how many bytes are read in the input buffer |
163 | 162 | size_t _outputBufferSize = 0; // how many bytes are written in the output buffer |
164 | - char_type* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
165 | - char_type* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
163 | + uint8_t* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
164 | + uint8_t* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
166 | 165 | }; |
@@ -1,8 +1,7 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../compression_interface.h" | |
3 | - | |
4 | 2 | #include "deflate_properties.h" |
5 | - | |
3 | +#include "../compression_interface.h" | |
4 | +#include "../../utils/stream/serialization.h" | |
6 | 5 | #include "../../extlibs/zlib/zlib.h" |
7 | 6 | |
8 | 7 | #include <cstdint> |
@@ -41,18 +40,18 @@ class deflate_encoder | ||
41 | 40 | _bufferCapacity = deflateProps.BufferCapacity; |
42 | 41 | |
43 | 42 | uninit_buffers(); |
44 | - _inputBuffer = new char_type[_bufferCapacity]; | |
45 | - _outputBuffer = new char_type[_bufferCapacity]; | |
43 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
44 | + _outputBuffer = new uint8_t[_bufferCapacity]; | |
46 | 45 | |
47 | 46 | // init deflate |
48 | - _zstream.zalloc = nullptr; | |
49 | - _zstream.zfree = nullptr; | |
50 | - _zstream.opaque = nullptr; | |
47 | + _zstream.zalloc = nullptr; | |
48 | + _zstream.zfree = nullptr; | |
49 | + _zstream.opaque = nullptr; | |
51 | 50 | |
52 | - _zstream.next_in = nullptr; | |
53 | - _zstream.next_out = nullptr; | |
54 | - _zstream.avail_in = 0; | |
55 | - _zstream.avail_out = 0; | |
51 | + _zstream.next_in = nullptr; | |
52 | + _zstream.next_out = nullptr; | |
53 | + _zstream.avail_in = 0; | |
54 | + _zstream.avail_out = 0; | |
56 | 55 | |
57 | 56 | deflateInit2(&_zstream, deflateProps.CompressionLevel, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY); |
58 | 57 | } |
@@ -62,12 +61,12 @@ class deflate_encoder | ||
62 | 61 | return _stream != nullptr; |
63 | 62 | } |
64 | 63 | |
65 | - char_type* get_buffer_begin() override | |
64 | + uint8_t* get_buffer_begin() override | |
66 | 65 | { |
67 | 66 | return _inputBuffer; |
68 | 67 | } |
69 | 68 | |
70 | - char_type* get_buffer_end() override | |
69 | + uint8_t* get_buffer_end() override | |
71 | 70 | { |
72 | 71 | return _inputBuffer + _bufferCapacity; |
73 | 72 | } |
@@ -93,7 +92,7 @@ class deflate_encoder | ||
93 | 92 | |
94 | 93 | if (have > 0) |
95 | 94 | { |
96 | - _stream->write(_outputBuffer, have); | |
95 | + utils::stream::serialize(*_stream, _outputBuffer, have); | |
97 | 96 | } |
98 | 97 | } while (_zstream.avail_out == 0); |
99 | 98 | } |
@@ -121,6 +120,6 @@ class deflate_encoder | ||
121 | 120 | std::ostream* _stream = nullptr; |
122 | 121 | |
123 | 122 | size_t _bufferCapacity = 0; |
124 | - char_type* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
125 | - char_type* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
123 | + uint8_t* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
124 | + uint8_t* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
126 | 125 | }; |
@@ -15,7 +15,6 @@ namespace detail | ||
15 | 15 | public: |
16 | 16 | friend class ::lzma_encoder; |
17 | 17 | |
18 | - typedef char char_type; | |
19 | 18 | typedef std::condition_variable event_type; |
20 | 19 | typedef std::mutex mutex_type; |
21 | 20 |
@@ -33,8 +32,8 @@ namespace detail | ||
33 | 32 | size_t lastBytesRead = _bytesRead; |
34 | 33 | |
35 | 34 | // set buffer pointer and get required size |
36 | - _internalInputBuffer = static_cast<char_type*>(buf); | |
37 | - _internalBufferSize = *size / sizeof(char_type); | |
35 | + _internalInputBuffer = static_cast<uint8_t*>(buf); | |
36 | + _internalBufferSize = *size; | |
38 | 37 | |
39 | 38 | // give control back to the main thread |
40 | 39 | set_event(); |
@@ -59,13 +58,13 @@ namespace detail | ||
59 | 58 | private: |
60 | 59 | size_t _bytesRead = 0; |
61 | 60 | size_t _internalBufferSize = 0; |
62 | - char_type* _internalInputBuffer = nullptr; | |
61 | + uint8_t* _internalInputBuffer = nullptr; | |
63 | 62 | event_type _event; |
64 | 63 | mutex_type _mutex; |
65 | 64 | bool _endOfStream = false; |
66 | 65 | |
67 | - char_type* get_buffer_begin() { return _internalInputBuffer; } | |
68 | - char_type* get_buffer_end() { return _internalInputBuffer + _internalBufferSize; } | |
66 | + uint8_t* get_buffer_begin() { return _internalInputBuffer; } | |
67 | + uint8_t* get_buffer_end() { return _internalInputBuffer + _internalBufferSize; } | |
69 | 68 | |
70 | 69 | void set_event() |
71 | 70 | { |
@@ -1,4 +1,5 @@ | ||
1 | 1 | #pragma once |
2 | +#include "../../../utils/stream/serialization.h" | |
2 | 3 | #include "../../../extlibs/lzma/Types.h" |
3 | 4 | |
4 | 5 | namespace detail |
@@ -7,8 +8,6 @@ namespace detail | ||
7 | 8 | : public ISeqOutStream |
8 | 9 | { |
9 | 10 | public: |
10 | - typedef char char_type; | |
11 | - | |
12 | 11 | lzma_out_stream() |
13 | 12 | { |
14 | 13 | this->Write = [](void* p, const void* buf, size_t size) |
@@ -21,7 +20,7 @@ namespace detail | ||
21 | 20 | size_t write(const void* buf, size_t size) |
22 | 21 | { |
23 | 22 | auto currentPosition = _stream->tellp(); |
24 | - _stream->write(reinterpret_cast<const char_type*>(buf), size); | |
23 | + utils::stream::serialize(*_stream, buf, size); | |
25 | 24 | |
26 | 25 | size_t delta = static_cast<size_t>(_stream->tellp()) - static_cast<size_t>(currentPosition); |
27 | 26 |
@@ -1,9 +1,8 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../compression_interface.h" | |
3 | - | |
4 | -#include "detail/lzma_alloc.h" | |
5 | 2 | #include "lzma_properties.h" |
6 | - | |
3 | +#include "detail/lzma_alloc.h" | |
4 | +#include "../compression_interface.h" | |
5 | +#include "../../utils/stream/serialization.h" | |
7 | 6 | #include "../../extlibs/lzma/LzmaDec.h" |
8 | 7 | |
9 | 8 | #include <cstdint> |
@@ -46,12 +45,12 @@ class lzma_decoder | ||
46 | 45 | _bufferCapacity = lzmaProps.BufferCapacity; |
47 | 46 | |
48 | 47 | uninit_buffers(); |
49 | - _inputBuffer = new char_type[_bufferCapacity]; | |
50 | - _outputBuffer = new char_type[_bufferCapacity]; | |
48 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
49 | + _outputBuffer = new uint8_t[_bufferCapacity]; | |
51 | 50 | |
52 | 51 | // read lzma header |
53 | - Byte header[LZMA_PROPS_SIZE + 4]; | |
54 | - _stream->read(reinterpret_cast<char_type*>(header), sizeof(header) / sizeof(char_type)); | |
52 | + Byte header[detail::lzma_header::HEADER_SIZE]; | |
53 | + utils::stream::deserialize(*_stream, header); | |
55 | 54 | |
56 | 55 | // init lzma |
57 | 56 | LzmaDec_Allocate(&_handle, &header[4], LZMA_PROPS_SIZE, &_alloc); |
@@ -63,12 +62,12 @@ class lzma_decoder | ||
63 | 62 | return (_inputBuffer != nullptr && _outputBuffer != nullptr); |
64 | 63 | } |
65 | 64 | |
66 | - char_type* get_buffer_begin() override | |
65 | + uint8_t* get_buffer_begin() override | |
67 | 66 | { |
68 | 67 | return _outputBuffer; |
69 | 68 | } |
70 | 69 | |
71 | - char_type* get_buffer_end() override | |
70 | + uint8_t* get_buffer_end() override | |
72 | 71 | { |
73 | 72 | return _outputBuffer + _outputBufferSize; |
74 | 73 | } |
@@ -122,7 +121,7 @@ class lzma_decoder | ||
122 | 121 | void read_next() |
123 | 122 | { |
124 | 123 | // read next bytes from input stream |
125 | - _stream->read(_inputBuffer, _bufferCapacity); | |
124 | + utils::stream::deserialize(*_stream, _inputBuffer, _bufferCapacity); | |
126 | 125 | |
127 | 126 | // set the size of buffer |
128 | 127 | _inputBufferSize = static_cast<size_t>(_stream->gcount()); |
@@ -143,6 +142,6 @@ class lzma_decoder | ||
143 | 142 | size_t _bufferCapacity = 0; |
144 | 143 | size_t _inputBufferSize = 0; // how many bytes are read in the input buffer |
145 | 144 | size_t _outputBufferSize = 0; // how many bytes are written in the output buffer |
146 | - char_type* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
147 | - char_type* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
145 | + uint8_t* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
146 | + uint8_t* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
148 | 147 | }; |
@@ -1,13 +1,15 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../compression_interface.h" | |
3 | - | |
4 | 2 | #include "lzma_properties.h" |
3 | + | |
5 | 4 | #include "detail/lzma_alloc.h" |
6 | 5 | #include "detail/lzma_handle.h" |
7 | 6 | #include "detail/lzma_header.h" |
8 | 7 | #include "detail/lzma_in_stream.h" |
9 | 8 | #include "detail/lzma_out_stream.h" |
10 | 9 | |
10 | +#include "../compression_interface.h" | |
11 | +#include "../../utils/stream/serialization.h" | |
12 | + | |
11 | 13 | #include <ostream> |
12 | 14 | #include <thread> |
13 | 15 | #include <cstdint> |
@@ -50,12 +52,12 @@ class lzma_encoder | ||
50 | 52 | return &_ostream.get_stream() != nullptr; |
51 | 53 | } |
52 | 54 | |
53 | - char_type* get_buffer_begin() override | |
55 | + uint8_t* get_buffer_begin() override | |
54 | 56 | { |
55 | 57 | return _istream.get_buffer_begin(); |
56 | 58 | } |
57 | 59 | |
58 | - char_type* get_buffer_end() override | |
60 | + uint8_t* get_buffer_end() override | |
59 | 61 | { |
60 | 62 | return _istream.get_buffer_end(); |
61 | 63 | } |
@@ -1,9 +1,8 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../compression_interface.h" | |
3 | - | |
4 | 2 | #include "store_properties.h" |
5 | - | |
3 | +#include "../compression_interface.h" | |
6 | 4 | #include "../../streams/crc32stream.h" |
5 | +#include "../../utils/stream/serialization.h" | |
7 | 6 | #include "../../extlibs/zlib/zlib.h" |
8 | 7 | |
9 | 8 | #include <cstdint> |
@@ -44,7 +43,7 @@ class store_decoder | ||
44 | 43 | _bufferCapacity = storeProps.BufferCapacity; |
45 | 44 | |
46 | 45 | uninit_buffers(); |
47 | - _outputBuffer = new char_type[_bufferCapacity]; | |
46 | + _outputBuffer = new uint8_t[_bufferCapacity]; | |
48 | 47 | } |
49 | 48 | |
50 | 49 | bool is_init() const override |
@@ -52,12 +51,12 @@ class store_decoder | ||
52 | 51 | return (_outputBuffer != nullptr); |
53 | 52 | } |
54 | 53 | |
55 | - char_type* get_buffer_begin() override | |
54 | + uint8_t* get_buffer_begin() override | |
56 | 55 | { |
57 | 56 | return _outputBuffer; |
58 | 57 | } |
59 | 58 | |
60 | - char_type* get_buffer_end() override | |
59 | + uint8_t* get_buffer_end() override | |
61 | 60 | { |
62 | 61 | return _outputBuffer + _outputBufferSize; |
63 | 62 | } |
@@ -65,7 +64,7 @@ class store_decoder | ||
65 | 64 | size_t decode_next() override |
66 | 65 | { |
67 | 66 | // read next bytes from input stream |
68 | - _stream->read(_outputBuffer, _bufferCapacity); | |
67 | + utils::stream::deserialize(*_stream, _outputBuffer, _bufferCapacity); | |
69 | 68 | |
70 | 69 | // set the size of buffer |
71 | 70 | _outputBufferSize = static_cast<size_t>(_stream->gcount()); |
@@ -84,5 +83,5 @@ class store_decoder | ||
84 | 83 | |
85 | 84 | size_t _bufferCapacity = 0; |
86 | 85 | size_t _outputBufferSize = 0; // how many bytes are written in the output buffer |
87 | - char_type* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
86 | + uint8_t* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
88 | 87 | }; |
@@ -1,9 +1,8 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../compression_interface.h" | |
3 | - | |
4 | 2 | #include "store_properties.h" |
5 | - | |
3 | +#include "../compression_interface.h" | |
6 | 4 | #include "../../streams/crc32stream.h" |
5 | +#include "../../utils/stream/serialization.h" | |
7 | 6 | #include "../../extlibs/zlib/zlib.h" |
8 | 7 | |
9 | 8 | #include <cstdint> |
@@ -41,8 +40,8 @@ class store_encoder | ||
41 | 40 | _bufferCapacity = storeProps.BufferCapacity; |
42 | 41 | |
43 | 42 | uninit_buffers(); |
44 | - _inputBuffer = new char_type[_bufferCapacity]; | |
45 | - _outputBuffer = new char_type[_bufferCapacity]; | |
43 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
44 | + _outputBuffer = new uint8_t[_bufferCapacity]; | |
46 | 45 | } |
47 | 46 | |
48 | 47 | bool is_init() const override |
@@ -50,19 +49,19 @@ class store_encoder | ||
50 | 49 | return _stream != nullptr; |
51 | 50 | } |
52 | 51 | |
53 | - char_type* get_buffer_begin() override | |
52 | + uint8_t* get_buffer_begin() override | |
54 | 53 | { |
55 | 54 | return _inputBuffer; |
56 | 55 | } |
57 | 56 | |
58 | - char_type* get_buffer_end() override | |
57 | + uint8_t* get_buffer_end() override | |
59 | 58 | { |
60 | 59 | return _inputBuffer + _bufferCapacity; |
61 | 60 | } |
62 | 61 | |
63 | 62 | void encode_next(size_t length) override |
64 | 63 | { |
65 | - _stream->write(_inputBuffer, length); | |
64 | + utils::stream::serialize(*_stream, _inputBuffer, length); | |
66 | 65 | } |
67 | 66 | |
68 | 67 | void sync() override |
@@ -80,6 +79,6 @@ class store_encoder | ||
80 | 79 | std::ostream* _stream = nullptr; |
81 | 80 | |
82 | 81 | size_t _bufferCapacity = 0; |
83 | - char_type* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
84 | - char_type* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
82 | + uint8_t* _inputBuffer = nullptr; // pointer to the start of the input buffer | |
83 | + uint8_t* _outputBuffer = nullptr; // pointer to the start of the output buffer | |
85 | 84 | }; |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #include "EndOfCentralDirectoryBlock.h" |
2 | -#include "../streams/serialization.h" | |
2 | +#include "../utils/stream/serialization.h" | |
3 | 3 | #include <cstring> |
4 | 4 | |
5 | 5 | namespace detail { |
@@ -15,21 +15,21 @@ bool EndOfCentralDirectoryBlock::Deserialize(std::istream& stream) | ||
15 | 15 | // this condition should be optimized out :) |
16 | 16 | if (sizeof(EndOfCentralDirectoryBlockBase) == EndOfCentralDirectoryBlockBase::SIZE_IN_BYTES) |
17 | 17 | { |
18 | - deserialize<EndOfCentralDirectoryBlockBase>(stream, *this); | |
18 | + utils::stream::deserialize<EndOfCentralDirectoryBlockBase>(stream, *this); | |
19 | 19 | } |
20 | 20 | else |
21 | 21 | { |
22 | - deserialize(stream, Signature); | |
23 | - deserialize(stream, NumberOfThisDisk); | |
24 | - deserialize(stream, NumberOfTheDiskWithTheStartOfTheCentralDirectory); | |
25 | - deserialize(stream, NumberOfEntriesInTheCentralDirectoryOnThisDisk); | |
26 | - deserialize(stream, NumberOfEntriesInTheCentralDirectory); | |
27 | - deserialize(stream, SizeOfCentralDirectory); | |
28 | - deserialize(stream, OffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber); | |
29 | - deserialize(stream, CommentLength); | |
22 | + utils::stream::deserialize(stream, Signature); | |
23 | + utils::stream::deserialize(stream, NumberOfThisDisk); | |
24 | + utils::stream::deserialize(stream, NumberOfTheDiskWithTheStartOfTheCentralDirectory); | |
25 | + utils::stream::deserialize(stream, NumberOfEntriesInTheCentralDirectoryOnThisDisk); | |
26 | + utils::stream::deserialize(stream, NumberOfEntriesInTheCentralDirectory); | |
27 | + utils::stream::deserialize(stream, SizeOfCentralDirectory); | |
28 | + utils::stream::deserialize(stream, OffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber); | |
29 | + utils::stream::deserialize(stream, CommentLength); | |
30 | 30 | } |
31 | 31 | |
32 | - deserialize(stream, Comment, CommentLength); | |
32 | + utils::stream::deserialize(stream, Comment, CommentLength); | |
33 | 33 | |
34 | 34 | return true; |
35 | 35 | } |
@@ -40,21 +40,21 @@ void EndOfCentralDirectoryBlock::Serialize(std::ostream& stream) | ||
40 | 40 | |
41 | 41 | if (sizeof(EndOfCentralDirectoryBlockBase) == EndOfCentralDirectoryBlockBase::SIZE_IN_BYTES) |
42 | 42 | { |
43 | - serialize<EndOfCentralDirectoryBlockBase>(stream, *this); | |
43 | + utils::stream::serialize<EndOfCentralDirectoryBlockBase>(stream, *this); | |
44 | 44 | } |
45 | 45 | else |
46 | 46 | { |
47 | - serialize(stream, Signature); | |
48 | - serialize(stream, NumberOfThisDisk); | |
49 | - serialize(stream, NumberOfTheDiskWithTheStartOfTheCentralDirectory); | |
50 | - serialize(stream, NumberOfEntriesInTheCentralDirectoryOnThisDisk); | |
51 | - serialize(stream, NumberOfEntriesInTheCentralDirectory); | |
52 | - serialize(stream, SizeOfCentralDirectory); | |
53 | - serialize(stream, OffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber); | |
54 | - serialize(stream, CommentLength); | |
47 | + utils::stream::serialize(stream, Signature); | |
48 | + utils::stream::serialize(stream, NumberOfThisDisk); | |
49 | + utils::stream::serialize(stream, NumberOfTheDiskWithTheStartOfTheCentralDirectory); | |
50 | + utils::stream::serialize(stream, NumberOfEntriesInTheCentralDirectoryOnThisDisk); | |
51 | + utils::stream::serialize(stream, NumberOfEntriesInTheCentralDirectory); | |
52 | + utils::stream::serialize(stream, SizeOfCentralDirectory); | |
53 | + utils::stream::serialize(stream, OffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber); | |
54 | + utils::stream::serialize(stream, CommentLength); | |
55 | 55 | } |
56 | 56 | |
57 | - serialize(stream, Comment); | |
57 | + utils::stream::serialize(stream, Comment); | |
58 | 58 | } |
59 | 59 | |
60 | 60 | } |
@@ -1,7 +1,7 @@ | ||
1 | 1 | #include "ZipCentralDirectoryFileHeader.h" |
2 | 2 | #include "ZipLocalFileHeader.h" |
3 | 3 | |
4 | -#include "../streams/serialization.h" | |
4 | +#include "../utils/stream/serialization.h" | |
5 | 5 | |
6 | 6 | #include <cstring> |
7 | 7 | #include <ctime> |
@@ -28,27 +28,27 @@ bool ZipCentralDirectoryFileHeader::Deserialize(std::istream& stream) | ||
28 | 28 | { |
29 | 29 | if (sizeof(ZipCentralDirectoryFileHeaderBase) == ZipCentralDirectoryFileHeaderBase::SIZE_IN_BYTES) |
30 | 30 | { |
31 | - deserialize<ZipCentralDirectoryFileHeaderBase>(stream, *this); | |
31 | + utils::stream::deserialize<ZipCentralDirectoryFileHeaderBase>(stream, *this); | |
32 | 32 | } |
33 | 33 | else |
34 | 34 | { |
35 | - deserialize(stream, Signature); | |
36 | - deserialize(stream, VersionMadeBy); | |
37 | - deserialize(stream, VersionNeededToExtract); | |
38 | - deserialize(stream, GeneralPurposeBitFlag); | |
39 | - deserialize(stream, CompressionMethod); | |
40 | - deserialize(stream, LastModificationTime); | |
41 | - deserialize(stream, LastModificationDate); | |
42 | - deserialize(stream, Crc32); | |
43 | - deserialize(stream, CompressedSize); | |
44 | - deserialize(stream, UncompressedSize); | |
45 | - deserialize(stream, FilenameLength); | |
46 | - deserialize(stream, ExtraFieldLength); | |
47 | - deserialize(stream, FileCommentLength); | |
48 | - deserialize(stream, DiskNumberStart); | |
49 | - deserialize(stream, InternalFileAttributes); | |
50 | - deserialize(stream, ExternalFileAttributes); | |
51 | - deserialize(stream, RelativeOffsetOfLocalHeader); | |
35 | + utils::stream::deserialize(stream, Signature); | |
36 | + utils::stream::deserialize(stream, VersionMadeBy); | |
37 | + utils::stream::deserialize(stream, VersionNeededToExtract); | |
38 | + utils::stream::deserialize(stream, GeneralPurposeBitFlag); | |
39 | + utils::stream::deserialize(stream, CompressionMethod); | |
40 | + utils::stream::deserialize(stream, LastModificationTime); | |
41 | + utils::stream::deserialize(stream, LastModificationDate); | |
42 | + utils::stream::deserialize(stream, Crc32); | |
43 | + utils::stream::deserialize(stream, CompressedSize); | |
44 | + utils::stream::deserialize(stream, UncompressedSize); | |
45 | + utils::stream::deserialize(stream, FilenameLength); | |
46 | + utils::stream::deserialize(stream, ExtraFieldLength); | |
47 | + utils::stream::deserialize(stream, FileCommentLength); | |
48 | + utils::stream::deserialize(stream, DiskNumberStart); | |
49 | + utils::stream::deserialize(stream, InternalFileAttributes); | |
50 | + utils::stream::deserialize(stream, ExternalFileAttributes); | |
51 | + utils::stream::deserialize(stream, RelativeOffsetOfLocalHeader); | |
52 | 52 | } |
53 | 53 | |
54 | 54 | // If there is not any other entry. |
@@ -59,7 +59,7 @@ bool ZipCentralDirectoryFileHeader::Deserialize(std::istream& stream) | ||
59 | 59 | return false; |
60 | 60 | } |
61 | 61 | |
62 | - deserialize(stream, Filename, FilenameLength); | |
62 | + utils::stream::deserialize(stream, Filename, FilenameLength); | |
63 | 63 | |
64 | 64 | if (ExtraFieldLength > 0) |
65 | 65 | { |
@@ -73,7 +73,7 @@ bool ZipCentralDirectoryFileHeader::Deserialize(std::istream& stream) | ||
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | - deserialize(stream, FileComment, FileCommentLength); | |
76 | + utils::stream::deserialize(stream, FileComment, FileCommentLength); | |
77 | 77 | |
78 | 78 | return true; |
79 | 79 | } |
@@ -91,30 +91,30 @@ void ZipCentralDirectoryFileHeader::Serialize(std::ostream& stream) | ||
91 | 91 | |
92 | 92 | if (sizeof(ZipCentralDirectoryFileHeaderBase) == ZipCentralDirectoryFileHeaderBase::SIZE_IN_BYTES) |
93 | 93 | { |
94 | - serialize<ZipCentralDirectoryFileHeaderBase>(stream, *this); | |
94 | + utils::stream::serialize<ZipCentralDirectoryFileHeaderBase>(stream, *this); | |
95 | 95 | } |
96 | 96 | else |
97 | 97 | { |
98 | - serialize(stream, Signature); | |
99 | - serialize(stream, VersionMadeBy); | |
100 | - serialize(stream, VersionNeededToExtract); | |
101 | - serialize(stream, GeneralPurposeBitFlag); | |
102 | - serialize(stream, CompressionMethod); | |
103 | - serialize(stream, LastModificationTime); | |
104 | - serialize(stream, LastModificationDate); | |
105 | - serialize(stream, Crc32); | |
106 | - serialize(stream, CompressedSize); | |
107 | - serialize(stream, UncompressedSize); | |
108 | - serialize(stream, FilenameLength); | |
109 | - serialize(stream, ExtraFieldLength); | |
110 | - serialize(stream, FileCommentLength); | |
111 | - serialize(stream, DiskNumberStart); | |
112 | - serialize(stream, InternalFileAttributes); | |
113 | - serialize(stream, ExternalFileAttributes); | |
114 | - serialize(stream, RelativeOffsetOfLocalHeader); | |
98 | + utils::stream::serialize(stream, Signature); | |
99 | + utils::stream::serialize(stream, VersionMadeBy); | |
100 | + utils::stream::serialize(stream, VersionNeededToExtract); | |
101 | + utils::stream::serialize(stream, GeneralPurposeBitFlag); | |
102 | + utils::stream::serialize(stream, CompressionMethod); | |
103 | + utils::stream::serialize(stream, LastModificationTime); | |
104 | + utils::stream::serialize(stream, LastModificationDate); | |
105 | + utils::stream::serialize(stream, Crc32); | |
106 | + utils::stream::serialize(stream, CompressedSize); | |
107 | + utils::stream::serialize(stream, UncompressedSize); | |
108 | + utils::stream::serialize(stream, FilenameLength); | |
109 | + utils::stream::serialize(stream, ExtraFieldLength); | |
110 | + utils::stream::serialize(stream, FileCommentLength); | |
111 | + utils::stream::serialize(stream, DiskNumberStart); | |
112 | + utils::stream::serialize(stream, InternalFileAttributes); | |
113 | + utils::stream::serialize(stream, ExternalFileAttributes); | |
114 | + utils::stream::serialize(stream, RelativeOffsetOfLocalHeader); | |
115 | 115 | } |
116 | 116 | |
117 | - serialize(stream, Filename); | |
117 | + utils::stream::serialize(stream, Filename); | |
118 | 118 | |
119 | 119 | if (ExtraFieldLength > 0) |
120 | 120 | { |
@@ -124,7 +124,7 @@ void ZipCentralDirectoryFileHeader::Serialize(std::ostream& stream) | ||
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - serialize(stream, FileComment); | |
127 | + utils::stream::serialize(stream, FileComment); | |
128 | 128 | } |
129 | 129 | |
130 | 130 | } |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #include "ZipGenericExtraField.h" |
2 | -#include "../streams/serialization.h" | |
2 | +#include "../utils/stream/serialization.h" | |
3 | 3 | |
4 | 4 | namespace detail { |
5 | 5 |
@@ -10,15 +10,15 @@ bool ZipGenericExtraField::Deserialize(std::istream& stream, std::istream::pos_t | ||
10 | 10 | return false; |
11 | 11 | } |
12 | 12 | |
13 | - deserialize(stream, Tag); | |
14 | - deserialize(stream, Size); | |
13 | + utils::stream::deserialize(stream, Tag); | |
14 | + utils::stream::deserialize(stream, Size); | |
15 | 15 | |
16 | 16 | if ((extraFieldEnd - stream.tellg()) < Size) |
17 | 17 | { |
18 | 18 | return false; |
19 | 19 | } |
20 | 20 | |
21 | - deserialize(stream, Data, Size); | |
21 | + utils::stream::deserialize(stream, Data, Size); | |
22 | 22 | |
23 | 23 | return true; |
24 | 24 | } |
@@ -27,9 +27,9 @@ void ZipGenericExtraField::Serialize(std::ostream& stream) | ||
27 | 27 | { |
28 | 28 | Size = static_cast<uint16_t>(Data.size()); |
29 | 29 | |
30 | - serialize(stream, Tag); | |
31 | - serialize(stream, Size); | |
32 | - serialize(stream, Data); | |
30 | + utils::stream::serialize(stream, Tag); | |
31 | + utils::stream::serialize(stream, Size); | |
32 | + utils::stream::serialize(stream, Data); | |
33 | 33 | } |
34 | 34 | |
35 | 35 | } |
@@ -1,7 +1,7 @@ | ||
1 | 1 | #include "ZipLocalFileHeader.h" |
2 | 2 | #include "ZipCentralDirectoryFileHeader.h" |
3 | 3 | |
4 | -#include "../streams/serialization.h" | |
4 | +#include "../utils/stream/serialization.h" | |
5 | 5 | |
6 | 6 | #include <cstring> |
7 | 7 |
@@ -32,21 +32,21 @@ bool ZipLocalFileHeader::Deserialize(std::istream& stream) | ||
32 | 32 | { |
33 | 33 | if (sizeof(ZipLocalFileHeaderBase) == ZipLocalFileHeaderBase::SIZE_IN_BYTES) |
34 | 34 | { |
35 | - deserialize<ZipLocalFileHeaderBase>(stream, *this); | |
35 | + utils::stream::deserialize<ZipLocalFileHeaderBase>(stream, *this); | |
36 | 36 | } |
37 | 37 | else |
38 | 38 | { |
39 | - deserialize(stream, Signature); | |
40 | - deserialize(stream, VersionNeededToExtract); | |
41 | - deserialize(stream, GeneralPurposeBitFlag); | |
42 | - deserialize(stream, CompressionMethod); | |
43 | - deserialize(stream, LastModificationTime); | |
44 | - deserialize(stream, LastModificationDate); | |
45 | - deserialize(stream, Crc32); | |
46 | - deserialize(stream, CompressedSize); | |
47 | - deserialize(stream, UncompressedSize); | |
48 | - deserialize(stream, FilenameLength); | |
49 | - deserialize(stream, ExtraFieldLength); | |
39 | + utils::stream::deserialize(stream, Signature); | |
40 | + utils::stream::deserialize(stream, VersionNeededToExtract); | |
41 | + utils::stream::deserialize(stream, GeneralPurposeBitFlag); | |
42 | + utils::stream::deserialize(stream, CompressionMethod); | |
43 | + utils::stream::deserialize(stream, LastModificationTime); | |
44 | + utils::stream::deserialize(stream, LastModificationDate); | |
45 | + utils::stream::deserialize(stream, Crc32); | |
46 | + utils::stream::deserialize(stream, CompressedSize); | |
47 | + utils::stream::deserialize(stream, UncompressedSize); | |
48 | + utils::stream::deserialize(stream, FilenameLength); | |
49 | + utils::stream::deserialize(stream, ExtraFieldLength); | |
50 | 50 | } |
51 | 51 | |
52 | 52 | // If there is not any other entry. |
@@ -57,7 +57,7 @@ bool ZipLocalFileHeader::Deserialize(std::istream& stream) | ||
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | - deserialize(stream, Filename, FilenameLength); | |
60 | + utils::stream::deserialize(stream, Filename, FilenameLength); | |
61 | 61 | |
62 | 62 | if (ExtraFieldLength > 0) |
63 | 63 | { |
@@ -86,24 +86,24 @@ void ZipLocalFileHeader::Serialize(std::ostream& stream) | ||
86 | 86 | |
87 | 87 | if (sizeof(ZipLocalFileHeaderBase) == ZipLocalFileHeaderBase::SIZE_IN_BYTES) |
88 | 88 | { |
89 | - serialize<ZipLocalFileHeaderBase>(stream, *this); | |
89 | + utils::stream::serialize<ZipLocalFileHeaderBase>(stream, *this); | |
90 | 90 | } |
91 | 91 | else |
92 | 92 | { |
93 | - serialize(stream, Signature); | |
94 | - serialize(stream, VersionNeededToExtract); | |
95 | - serialize(stream, GeneralPurposeBitFlag); | |
96 | - serialize(stream, CompressionMethod); | |
97 | - serialize(stream, LastModificationTime); | |
98 | - serialize(stream, LastModificationDate); | |
99 | - serialize(stream, Crc32); | |
100 | - serialize(stream, CompressedSize); | |
101 | - serialize(stream, UncompressedSize); | |
102 | - serialize(stream, FilenameLength); | |
103 | - serialize(stream, ExtraFieldLength); | |
93 | + utils::stream::serialize(stream, Signature); | |
94 | + utils::stream::serialize(stream, VersionNeededToExtract); | |
95 | + utils::stream::serialize(stream, GeneralPurposeBitFlag); | |
96 | + utils::stream::serialize(stream, CompressionMethod); | |
97 | + utils::stream::serialize(stream, LastModificationTime); | |
98 | + utils::stream::serialize(stream, LastModificationDate); | |
99 | + utils::stream::serialize(stream, Crc32); | |
100 | + utils::stream::serialize(stream, CompressedSize); | |
101 | + utils::stream::serialize(stream, UncompressedSize); | |
102 | + utils::stream::serialize(stream, FilenameLength); | |
103 | + utils::stream::serialize(stream, ExtraFieldLength); | |
104 | 104 | } |
105 | 105 | |
106 | - serialize(stream, Filename); | |
106 | + utils::stream::serialize(stream, Filename); | |
107 | 107 | |
108 | 108 | if (ExtraFieldLength > 0) |
109 | 109 | { |
@@ -117,29 +117,29 @@ void ZipLocalFileHeader::Serialize(std::ostream& stream) | ||
117 | 117 | void ZipLocalFileHeader::DeserializeAsDataDescriptor(std::istream& stream) |
118 | 118 | { |
119 | 119 | uint32_t firstWord; |
120 | - deserialize(stream, firstWord); | |
120 | + utils::stream::deserialize(stream, firstWord); | |
121 | 121 | |
122 | 122 | // the signature is optional, if it's missing, |
123 | 123 | // we're starting with crc32 |
124 | 124 | if (firstWord != DataDescriptorSignature) |
125 | 125 | { |
126 | - deserialize(stream, Crc32); | |
126 | + utils::stream::deserialize(stream, Crc32); | |
127 | 127 | } |
128 | 128 | else |
129 | 129 | { |
130 | 130 | Crc32 = firstWord; |
131 | 131 | } |
132 | 132 | |
133 | - deserialize(stream, CompressedSize); | |
134 | - deserialize(stream, UncompressedSize); | |
133 | + utils::stream::deserialize(stream, CompressedSize); | |
134 | + utils::stream::deserialize(stream, UncompressedSize); | |
135 | 135 | } |
136 | 136 | |
137 | 137 | void ZipLocalFileHeader::SerializeAsDataDescriptor(std::ostream& stream) |
138 | 138 | { |
139 | - serialize(stream, DataDescriptorSignature); | |
140 | - serialize(stream, Crc32); | |
141 | - serialize(stream, CompressedSize); | |
142 | - serialize(stream, UncompressedSize); | |
139 | + utils::stream::serialize(stream, DataDescriptorSignature); | |
140 | + utils::stream::serialize(stream, Crc32); | |
141 | + utils::stream::serialize(stream, CompressedSize); | |
142 | + utils::stream::serialize(stream, UncompressedSize); | |
143 | 143 | } |
144 | 144 | |
145 | 145 | } |
@@ -1,8 +1,8 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../encryption_interface.h" | |
3 | -#include "../../streams/serialization.h" | |
4 | 2 | #include "aes_properties.h" |
5 | 3 | #include "detail/aes_impl.h" |
4 | +#include "../encryption_interface.h" | |
5 | +#include "../../utils/stream/serialization.h" | |
6 | 6 | |
7 | 7 | #include <cstdint> |
8 | 8 |
@@ -36,7 +36,7 @@ class aes_decoder | ||
36 | 36 | _bufferCapacity = aesProps.BufferCapacity; |
37 | 37 | |
38 | 38 | uninit_buffers(); |
39 | - _inputBuffer = new char_type[_bufferCapacity]; | |
39 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
40 | 40 | |
41 | 41 | // init stream |
42 | 42 | _stream = &stream; |
@@ -61,22 +61,22 @@ class aes_decoder | ||
61 | 61 | return _stream != nullptr && _encryptedStream != nullptr && _authCodeStream != nullptr; |
62 | 62 | } |
63 | 63 | |
64 | - char_type* get_buffer_begin() override | |
64 | + uint8_t* get_buffer_begin() override | |
65 | 65 | { |
66 | 66 | return _inputBuffer; |
67 | 67 | } |
68 | 68 | |
69 | - char_type* get_buffer_end() override | |
69 | + uint8_t* get_buffer_end() override | |
70 | 70 | { |
71 | 71 | return _inputBuffer + _bufferCapacity; |
72 | 72 | } |
73 | 73 | |
74 | 74 | size_t decrypt_next() override |
75 | 75 | { |
76 | - _encryptedStream->read(_inputBuffer, _bufferCapacity); | |
76 | + utils::stream::deserialize(*_encryptedStream, _inputBuffer, _bufferCapacity); | |
77 | 77 | |
78 | 78 | size_t n = static_cast<size_t>(_encryptedStream->gcount()); |
79 | - _aes.decrypt(reinterpret_cast<uint8_t*>(_inputBuffer), n); | |
79 | + _aes.decrypt(_inputBuffer, n); | |
80 | 80 | |
81 | 81 | _aesContext.authcode = _aes.finish(); |
82 | 82 |
@@ -115,15 +115,15 @@ class aes_decoder | ||
115 | 115 | |
116 | 116 | void read_encryption_header() |
117 | 117 | { |
118 | - deserialize(*_encryptedStream, _aesStoredContext.salt.data(), _aesStoredContext.salt.size()); | |
119 | - deserialize(*_encryptedStream, _aesStoredContext.passverify); | |
118 | + utils::stream::deserialize(*_encryptedStream, _aesStoredContext.salt.data(), _aesStoredContext.salt.size()); | |
119 | + utils::stream::deserialize(*_encryptedStream, _aesStoredContext.passverify); | |
120 | 120 | |
121 | 121 | _encryptionHeaderRead = true; |
122 | 122 | } |
123 | 123 | |
124 | 124 | void read_encryption_footer() |
125 | 125 | { |
126 | - deserialize(*_authCodeStream, _aesStoredContext.authcode); | |
126 | + utils::stream::deserialize(*_authCodeStream, _aesStoredContext.authcode); | |
127 | 127 | |
128 | 128 | _encryptionFooterRead = true; |
129 | 129 | } |
@@ -133,10 +133,10 @@ class aes_decoder | ||
133 | 133 | delete[] _inputBuffer; |
134 | 134 | } |
135 | 135 | |
136 | - char_type* _inputBuffer = nullptr; | |
137 | - size_t _bufferCapacity = 0; | |
136 | + uint8_t* _inputBuffer = nullptr; | |
137 | + size_t _bufferCapacity = 0; | |
138 | 138 | |
139 | - std::istream* _stream = nullptr; | |
139 | + std::istream* _stream = nullptr; | |
140 | 140 | std::unique_ptr<isubstream> _encryptedStream; |
141 | 141 | std::unique_ptr<isubstream> _authCodeStream; |
142 | 142 |
@@ -157,6 +157,6 @@ class aes_decoder | ||
157 | 157 | aes_context _aesContext; |
158 | 158 | aes_stored_context _aesStoredContext; |
159 | 159 | |
160 | - bool _encryptionHeaderRead = false; | |
161 | - bool _encryptionFooterRead = false; | |
160 | + bool _encryptionHeaderRead = false; | |
161 | + bool _encryptionFooterRead = false; | |
162 | 162 | }; |
@@ -1,8 +1,8 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../encryption_interface.h" | |
3 | -#include "../../streams/serialization.h" | |
4 | 2 | #include "aes_properties.h" |
5 | 3 | #include "detail/aes_impl.h" |
4 | +#include "../encryption_interface.h" | |
5 | +#include "../../utils/stream/serialization.h" | |
6 | 6 | |
7 | 7 | #include <cstdint> |
8 | 8 |
@@ -36,7 +36,7 @@ class aes_encoder | ||
36 | 36 | _bufferCapacity = aesProps.BufferCapacity; |
37 | 37 | |
38 | 38 | uninit_buffers(); |
39 | - _inputBuffer = new char_type[_bufferCapacity]; | |
39 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
40 | 40 | |
41 | 41 | // init stream |
42 | 42 | _stream = &stream; |
@@ -54,12 +54,12 @@ class aes_encoder | ||
54 | 54 | return _stream != nullptr; |
55 | 55 | } |
56 | 56 | |
57 | - char_type* get_buffer_begin() override | |
57 | + uint8_t* get_buffer_begin() override | |
58 | 58 | { |
59 | 59 | return _inputBuffer; |
60 | 60 | } |
61 | 61 | |
62 | - char_type* get_buffer_end() override | |
62 | + uint8_t* get_buffer_end() override | |
63 | 63 | { |
64 | 64 | return _inputBuffer + _bufferCapacity; |
65 | 65 | } |
@@ -71,21 +71,21 @@ class aes_encoder | ||
71 | 71 | write_encryption_header(); |
72 | 72 | } |
73 | 73 | |
74 | - _aes.encrypt(reinterpret_cast<uint8_t*>(_inputBuffer), length); | |
75 | - _stream->write(_inputBuffer, length); | |
74 | + _aes.encrypt(_inputBuffer, length); | |
75 | + utils::stream::serialize(*_stream, _inputBuffer, length); | |
76 | 76 | } |
77 | 77 | |
78 | 78 | void sync() override |
79 | 79 | { |
80 | - serialize(*_stream, _aes.finish()); | |
80 | + utils::stream::serialize(*_stream, _aes.finish()); | |
81 | 81 | _stream->rdbuf()->pubsync(); |
82 | 82 | } |
83 | 83 | |
84 | 84 | private: |
85 | 85 | void write_encryption_header() |
86 | 86 | { |
87 | - serialize(*_stream, _aesContext.salt.data(), _aesContext.salt.size()); | |
88 | - serialize(*_stream, _aesContext.passverify); | |
87 | + utils::stream::serialize(*_stream, _aesContext.salt.data(), _aesContext.salt.size()); | |
88 | + utils::stream::serialize(*_stream, _aesContext.passverify); | |
89 | 89 | |
90 | 90 | _encryptionHeaderWritten = true; |
91 | 91 | } |
@@ -95,7 +95,7 @@ class aes_encoder | ||
95 | 95 | delete[] _inputBuffer; |
96 | 96 | } |
97 | 97 | |
98 | - char_type* _inputBuffer = nullptr; | |
98 | + uint8_t* _inputBuffer = nullptr; | |
99 | 99 | size_t _bufferCapacity = 0; |
100 | 100 | |
101 | 101 | std::ostream* _stream = nullptr; |
@@ -6,9 +6,9 @@ namespace detail { | ||
6 | 6 | |
7 | 7 | enum |
8 | 8 | { |
9 | - AES_PASSWORD_VERIFY_SIZE = 2, | |
10 | - AES_AUTHCODE_SIZE = 10, | |
11 | - AES_MAX_SALT_LENGTH = 16 | |
9 | + AES_PASSWORD_VERIFY_SIZE = 2, | |
10 | + AES_AUTHCODE_SIZE = 10, | |
11 | + AES_MAX_SALT_LENGTH = 16 | |
12 | 12 | }; |
13 | 13 | |
14 | 14 | using aes_passverify = std::array<uint8_t, AES_PASSWORD_VERIFY_SIZE>; |
@@ -21,14 +21,12 @@ struct encryption_properties_interface | ||
21 | 21 | class encryption_interface |
22 | 22 | { |
23 | 23 | public: |
24 | - typedef char char_type; | |
25 | - | |
26 | 24 | virtual ~encryption_interface() { } |
27 | 25 | |
28 | 26 | virtual bool is_init() const = 0; |
29 | 27 | |
30 | - virtual char_type* get_buffer_begin() = 0; | |
31 | - virtual char_type* get_buffer_end() = 0; | |
28 | + virtual uint8_t* get_buffer_begin() = 0; | |
29 | + virtual uint8_t* get_buffer_end() = 0; | |
32 | 30 | }; |
33 | 31 | |
34 | 32 | class encryption_encoder_interface |
@@ -1,8 +1,9 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../encryption_interface.h" | |
3 | 2 | #include "zipcrypto_properties.h" |
4 | -#include "../../extlibs/zlib/zconf.h" | |
5 | 3 | #include "detail/zipcrypto.h" |
4 | +#include "../encryption_interface.h" | |
5 | +#include "../../utils/stream/serialization.h" | |
6 | +#include "../../extlibs/zlib/zconf.h" | |
6 | 7 | |
7 | 8 | #include <cstdint> |
8 | 9 |
@@ -36,7 +37,7 @@ class zipcrypto_decoder | ||
36 | 37 | _bufferCapacity = zipcryptoProps.BufferCapacity; |
37 | 38 | |
38 | 39 | uninit_buffers(); |
39 | - _inputBuffer = new char_type[_bufferCapacity]; | |
40 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
40 | 41 | |
41 | 42 | // init stream |
42 | 43 | _stream = &stream; |
@@ -57,12 +58,12 @@ class zipcrypto_decoder | ||
57 | 58 | return _stream != nullptr; |
58 | 59 | } |
59 | 60 | |
60 | - char_type* get_buffer_begin() override | |
61 | + uint8_t* get_buffer_begin() override | |
61 | 62 | { |
62 | 63 | return _inputBuffer; |
63 | 64 | } |
64 | 65 | |
65 | - char_type* get_buffer_end() override | |
66 | + uint8_t* get_buffer_end() override | |
66 | 67 | { |
67 | 68 | return _inputBuffer + _bufferCapacity; |
68 | 69 | } |
@@ -74,10 +75,10 @@ class zipcrypto_decoder | ||
74 | 75 | read_encryption_header(); |
75 | 76 | } |
76 | 77 | |
77 | - _stream->read(_inputBuffer, _bufferCapacity); | |
78 | + utils::stream::deserialize(*_stream, _inputBuffer, _bufferCapacity); | |
78 | 79 | |
79 | 80 | size_t n = static_cast<size_t>(_stream->gcount()); |
80 | - _zipcrypto.decrypt_buffer(reinterpret_cast<uint8_t*>(_inputBuffer), n); | |
81 | + _zipcrypto.decrypt_buffer(_inputBuffer, n); | |
81 | 82 | |
82 | 83 | return n; |
83 | 84 | } |
@@ -90,9 +91,10 @@ class zipcrypto_decoder | ||
90 | 91 | private: |
91 | 92 | void read_encryption_header() |
92 | 93 | { |
93 | - _stream->read( | |
94 | - reinterpret_cast<char_type*>(&_zipcrypto.get_encryption_header()), | |
95 | - _zipcrypto.get_encryption_header_size()); | |
94 | + utils::stream::deserialize( | |
95 | + *_stream, | |
96 | + &_zipcrypto.get_encryption_header(), | |
97 | + _zipcrypto.get_encryption_header_size()); | |
96 | 98 | |
97 | 99 | _zipcrypto.decrypt_header(); |
98 | 100 | _encryptionHeaderRead = true; |
@@ -103,10 +105,10 @@ class zipcrypto_decoder | ||
103 | 105 | delete[] _inputBuffer; |
104 | 106 | } |
105 | 107 | |
106 | - char_type* _inputBuffer = nullptr; | |
107 | - size_t _bufferCapacity = 0; | |
108 | + uint8_t* _inputBuffer = nullptr; | |
109 | + size_t _bufferCapacity = 0; | |
108 | 110 | |
109 | - std::istream* _stream = nullptr; | |
111 | + std::istream* _stream = nullptr; | |
110 | 112 | detail::zipcrypto _zipcrypto; |
111 | - bool _encryptionHeaderRead = false; | |
113 | + bool _encryptionHeaderRead = false; | |
112 | 114 | }; |
@@ -1,7 +1,8 @@ | ||
1 | 1 | #pragma once |
2 | -#include "../encryption_interface.h" | |
3 | 2 | #include "zipcrypto_properties.h" |
4 | 3 | #include "detail/zipcrypto.h" |
4 | +#include "../encryption_interface.h" | |
5 | +#include "../../utils/stream/serialization.h" | |
5 | 6 | |
6 | 7 | #include <cstdint> |
7 | 8 |
@@ -35,7 +36,7 @@ class zipcrypto_encoder | ||
35 | 36 | _bufferCapacity = zipcryptoProps.BufferCapacity; |
36 | 37 | |
37 | 38 | uninit_buffers(); |
38 | - _inputBuffer = new char_type[_bufferCapacity]; | |
39 | + _inputBuffer = new uint8_t[_bufferCapacity]; | |
39 | 40 | |
40 | 41 | // init stream |
41 | 42 | _stream = &stream; |
@@ -53,12 +54,12 @@ class zipcrypto_encoder | ||
53 | 54 | return _stream != nullptr; |
54 | 55 | } |
55 | 56 | |
56 | - char_type* get_buffer_begin() override | |
57 | + uint8_t* get_buffer_begin() override | |
57 | 58 | { |
58 | 59 | return _inputBuffer; |
59 | 60 | } |
60 | 61 | |
61 | - char_type* get_buffer_end() override | |
62 | + uint8_t* get_buffer_end() override | |
62 | 63 | { |
63 | 64 | return _inputBuffer + _bufferCapacity; |
64 | 65 | } |
@@ -70,8 +71,8 @@ class zipcrypto_encoder | ||
70 | 71 | write_encryption_header(); |
71 | 72 | } |
72 | 73 | |
73 | - _zipcrypto.encrypt_buffer(reinterpret_cast<uint8_t*>(_inputBuffer), length); | |
74 | - _stream->write(_inputBuffer, length); | |
74 | + _zipcrypto.encrypt_buffer(_inputBuffer, length); | |
75 | + utils::stream::serialize(*_stream, _inputBuffer, length); | |
75 | 76 | } |
76 | 77 | |
77 | 78 | void sync() override |
@@ -83,9 +84,11 @@ class zipcrypto_encoder | ||
83 | 84 | void write_encryption_header() |
84 | 85 | { |
85 | 86 | _zipcrypto.encrypt_header(); |
86 | - _stream->write( | |
87 | - reinterpret_cast<const char_type*>(&_zipcrypto.get_encryption_header()), | |
88 | - _zipcrypto.get_encryption_header_size()); | |
87 | + | |
88 | + utils::stream::serialize( | |
89 | + *_stream, | |
90 | + &_zipcrypto.get_encryption_header(), | |
91 | + _zipcrypto.get_encryption_header_size()); | |
89 | 92 | |
90 | 93 | _encryptionHeaderWritten = true; |
91 | 94 | } |
@@ -95,7 +98,7 @@ class zipcrypto_encoder | ||
95 | 98 | delete[] _inputBuffer; |
96 | 99 | } |
97 | 100 | |
98 | - char_type* _inputBuffer = nullptr; | |
101 | + uint8_t* _inputBuffer = nullptr; | |
99 | 102 | size_t _bufferCapacity = 0; |
100 | 103 | |
101 | 104 | std::ostream* _stream = nullptr; |
@@ -114,6 +114,7 @@ | ||
114 | 114 | <WarningLevel>Level3</WarningLevel> |
115 | 115 | <Optimization>Disabled</Optimization> |
116 | 116 | <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
117 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
117 | 118 | </ClCompile> |
118 | 119 | <Link> |
119 | 120 | <SubSystem>Windows</SubSystem> |
@@ -127,6 +128,7 @@ | ||
127 | 128 | <WarningLevel>Level3</WarningLevel> |
128 | 129 | <Optimization>Disabled</Optimization> |
129 | 130 | <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
131 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
130 | 132 | </ClCompile> |
131 | 133 | <Link> |
132 | 134 | <SubSystem>Windows</SubSystem> |
@@ -104,6 +104,7 @@ | ||
104 | 104 | <Optimization>Disabled</Optimization> |
105 | 105 | <PreprocessorDefinitions>WIN32;BZ_NO_STDIO;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
106 | 106 | <DisableSpecificWarnings>4996; 4244</DisableSpecificWarnings> |
107 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
107 | 108 | </ClCompile> |
108 | 109 | <Link> |
109 | 110 | <SubSystem>Windows</SubSystem> |
@@ -118,6 +119,7 @@ | ||
118 | 119 | <Optimization>Disabled</Optimization> |
119 | 120 | <PreprocessorDefinitions>WIN32;BZ_NO_STDIO;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
120 | 121 | <DisableSpecificWarnings>4996; 4244</DisableSpecificWarnings> |
122 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
121 | 123 | </ClCompile> |
122 | 124 | <Link> |
123 | 125 | <SubSystem>Windows</SubSystem> |
@@ -160,6 +160,7 @@ | ||
160 | 160 | <Optimization>Disabled</Optimization> |
161 | 161 | <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
162 | 162 | <DisableSpecificWarnings>4996</DisableSpecificWarnings> |
163 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
163 | 164 | </ClCompile> |
164 | 165 | <Link> |
165 | 166 | <SubSystem>Windows</SubSystem> |
@@ -174,6 +175,7 @@ | ||
174 | 175 | <Optimization>Disabled</Optimization> |
175 | 176 | <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
176 | 177 | <DisableSpecificWarnings>4996</DisableSpecificWarnings> |
178 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
177 | 179 | </ClCompile> |
178 | 180 | <Link> |
179 | 181 | <SubSystem>Windows</SubSystem> |
@@ -116,6 +116,7 @@ | ||
116 | 116 | <Optimization>Disabled</Optimization> |
117 | 117 | <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
118 | 118 | <DisableSpecificWarnings>4996</DisableSpecificWarnings> |
119 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
119 | 120 | </ClCompile> |
120 | 121 | <Link> |
121 | 122 | <SubSystem>Windows</SubSystem> |
@@ -130,6 +131,7 @@ | ||
130 | 131 | <Optimization>Disabled</Optimization> |
131 | 132 | <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
132 | 133 | <DisableSpecificWarnings>4996</DisableSpecificWarnings> |
134 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
133 | 135 | </ClCompile> |
134 | 136 | <Link> |
135 | 137 | <SubSystem>Windows</SubSystem> |
@@ -1,7 +1,7 @@ | ||
1 | 1 | #pragma once |
2 | 2 | #include "../../../detail/ZipGenericExtraField.h" |
3 | 3 | #include "../../../streams/memstream.h" |
4 | -#include "../../../streams/serialization.h" | |
4 | +#include "../../../utils/stream/serialization.h" | |
5 | 5 | #include <cstdint> |
6 | 6 | |
7 | 7 | namespace detail { |
@@ -36,10 +36,10 @@ namespace detail { | ||
36 | 36 | |
37 | 37 | uint16_t dummyVendorID; |
38 | 38 | |
39 | - deserialize(extraFieldDataStream, AesVersion); | |
40 | - deserialize(extraFieldDataStream, dummyVendorID); | |
41 | - deserialize(extraFieldDataStream, EncryptionMode); | |
42 | - deserialize(extraFieldDataStream, CompressionMethod); | |
39 | + utils::stream::deserialize(extraFieldDataStream, AesVersion); | |
40 | + utils::stream::deserialize(extraFieldDataStream, dummyVendorID); | |
41 | + utils::stream::deserialize(extraFieldDataStream, EncryptionMode); | |
42 | + utils::stream::deserialize(extraFieldDataStream, CompressionMethod); | |
43 | 43 | } |
44 | 44 | |
45 | 45 | void ToExtraField(detail::ZipGenericExtraField& extraField) |
@@ -51,10 +51,10 @@ namespace detail { | ||
51 | 51 | |
52 | 52 | omemstream extraFieldDataStream((char*)extraField.Data.data(), extraField.Data.size()); |
53 | 53 | |
54 | - serialize(extraFieldDataStream, AesVersion); | |
55 | - serialize(extraFieldDataStream, VendorID); | |
56 | - serialize(extraFieldDataStream, EncryptionMode); | |
57 | - serialize(extraFieldDataStream, CompressionMethod); | |
54 | + utils::stream::serialize(extraFieldDataStream, AesVersion); | |
55 | + utils::stream::serialize(extraFieldDataStream, VendorID); | |
56 | + utils::stream::serialize(extraFieldDataStream, EncryptionMode); | |
57 | + utils::stream::serialize(extraFieldDataStream, CompressionMethod); | |
58 | 58 | } |
59 | 59 | }; |
60 | 60 |
@@ -35,7 +35,7 @@ class compression_decoder_streambuf | ||
35 | 35 | _compressionDecoder->init(stream); |
36 | 36 | |
37 | 37 | // set stream buffer |
38 | - this->setg(_compressionDecoder->get_buffer_end(), _compressionDecoder->get_buffer_end(), _compressionDecoder->get_buffer_end()); | |
38 | + this->setg(get_buffer_end(), get_buffer_end(), get_buffer_end()); | |
39 | 39 | } |
40 | 40 | |
41 | 41 | void init(compression_decoder_interface_ptr compressionDecoder, compression_properties_interface& props, std::istream& stream) |
@@ -46,7 +46,7 @@ class compression_decoder_streambuf | ||
46 | 46 | _compressionDecoder->init(stream, props); |
47 | 47 | |
48 | 48 | // set stream buffer |
49 | - this->setg(_compressionDecoder->get_buffer_end(), _compressionDecoder->get_buffer_end(), _compressionDecoder->get_buffer_end()); | |
49 | + this->setg(get_buffer_end(), get_buffer_end(), get_buffer_end()); | |
50 | 50 | } |
51 | 51 | |
52 | 52 | bool is_init() const |
@@ -60,7 +60,7 @@ class compression_decoder_streambuf | ||
60 | 60 | // buffer exhausted |
61 | 61 | if (this->gptr() >= this->egptr()) |
62 | 62 | { |
63 | - char_type* base = _compressionDecoder->get_buffer_begin(); | |
63 | + char_type* base = get_buffer_begin(); | |
64 | 64 | |
65 | 65 | // how many bytes has been read |
66 | 66 | size_t n = _compressionDecoder->decode_next(); |
@@ -78,5 +78,15 @@ class compression_decoder_streambuf | ||
78 | 78 | } |
79 | 79 | |
80 | 80 | private: |
81 | + char_type* get_buffer_begin() | |
82 | + { | |
83 | + return reinterpret_cast<char_type*>(_compressionDecoder->get_buffer_begin()); | |
84 | + } | |
85 | + | |
86 | + char_type* get_buffer_end() | |
87 | + { | |
88 | + return reinterpret_cast<char_type*>(_compressionDecoder->get_buffer_end()); | |
89 | + } | |
90 | + | |
81 | 91 | compression_decoder_interface_ptr _compressionDecoder; |
82 | 92 | }; |
@@ -40,7 +40,7 @@ class compression_encoder_streambuf | ||
40 | 40 | _compressionEncoder->init(stream); |
41 | 41 | |
42 | 42 | // set stream buffer |
43 | - this->setp(_compressionEncoder->get_buffer_begin(), _compressionEncoder->get_buffer_end() - 1); | |
43 | + this->setp(get_buffer_begin(), get_buffer_end() - 1); | |
44 | 44 | } |
45 | 45 | |
46 | 46 | void init(compression_encoder_interface_ptr compressionEncoder, compression_properties_interface& props, std::ostream& stream) |
@@ -51,7 +51,7 @@ class compression_encoder_streambuf | ||
51 | 51 | _compressionEncoder->init(stream, props); |
52 | 52 | |
53 | 53 | // set stream buffer |
54 | - this->setp(_compressionEncoder->get_buffer_begin(), _compressionEncoder->get_buffer_end() - 1); | |
54 | + this->setp(get_buffer_begin(), get_buffer_end() - 1); | |
55 | 55 | } |
56 | 56 | |
57 | 57 | bool is_init() const |
@@ -98,7 +98,17 @@ class compression_encoder_streambuf | ||
98 | 98 | _compressionEncoder->encode_next(inputLength); |
99 | 99 | |
100 | 100 | // set pointers for new buffer |
101 | - this->setp(_compressionEncoder->get_buffer_begin(), _compressionEncoder->get_buffer_end() - 1); | |
101 | + this->setp(get_buffer_begin(), get_buffer_end() - 1); | |
102 | + } | |
103 | + | |
104 | + char_type* get_buffer_begin() | |
105 | + { | |
106 | + return reinterpret_cast<char_type*>(_compressionEncoder->get_buffer_begin()); | |
107 | + } | |
108 | + | |
109 | + char_type* get_buffer_end() | |
110 | + { | |
111 | + return reinterpret_cast<char_type*>(_compressionEncoder->get_buffer_end()); | |
102 | 112 | } |
103 | 113 | |
104 | 114 | compression_encoder_interface_ptr _compressionEncoder; |
@@ -35,7 +35,7 @@ class encryption_decoder_streambuf | ||
35 | 35 | _encryptionDecoder->init(stream); |
36 | 36 | |
37 | 37 | // set stream buffer |
38 | - this->setg(_encryptionDecoder->get_buffer_end(), _encryptionDecoder->get_buffer_end(), _encryptionDecoder->get_buffer_end()); | |
38 | + this->setg(get_buffer_end(), get_buffer_end(), get_buffer_end()); | |
39 | 39 | } |
40 | 40 | |
41 | 41 | void init(encryption_decoder_interface_ptr encryptionDecoder, encryption_properties_interface& props, std::istream& stream) |
@@ -46,7 +46,7 @@ class encryption_decoder_streambuf | ||
46 | 46 | _encryptionDecoder->init(stream, props); |
47 | 47 | |
48 | 48 | // set stream buffer |
49 | - this->setg(_encryptionDecoder->get_buffer_end(), _encryptionDecoder->get_buffer_end(), _encryptionDecoder->get_buffer_end()); | |
49 | + this->setg(get_buffer_end(), get_buffer_end(), get_buffer_end()); | |
50 | 50 | } |
51 | 51 | |
52 | 52 | bool is_init() const |
@@ -60,7 +60,7 @@ class encryption_decoder_streambuf | ||
60 | 60 | // buffer exhausted |
61 | 61 | if (this->gptr() >= this->egptr()) |
62 | 62 | { |
63 | - char_type* base = _encryptionDecoder->get_buffer_begin(); | |
63 | + char_type* base = get_buffer_begin(); | |
64 | 64 | |
65 | 65 | // how many bytes has been read |
66 | 66 | size_t n = _encryptionDecoder->decrypt_next(); |
@@ -78,5 +78,15 @@ class encryption_decoder_streambuf | ||
78 | 78 | } |
79 | 79 | |
80 | 80 | private: |
81 | + char_type* get_buffer_begin() | |
82 | + { | |
83 | + return reinterpret_cast<char_type*>(_encryptionDecoder->get_buffer_begin()); | |
84 | + } | |
85 | + | |
86 | + char_type* get_buffer_end() | |
87 | + { | |
88 | + return reinterpret_cast<char_type*>(_encryptionDecoder->get_buffer_end()); | |
89 | + } | |
90 | + | |
81 | 91 | encryption_decoder_interface_ptr _encryptionDecoder; |
82 | 92 | }; |
@@ -40,7 +40,7 @@ class encryption_encoder_streambuf | ||
40 | 40 | _encryptionEncoder->init(stream); |
41 | 41 | |
42 | 42 | // set stream buffer |
43 | - this->setp(_encryptionEncoder->get_buffer_begin(), _encryptionEncoder->get_buffer_end() - 1); | |
43 | + this->setp(get_buffer_begin(), get_buffer_end() - 1); | |
44 | 44 | } |
45 | 45 | |
46 | 46 | void init(encryption_encoder_interface_ptr encryptionEncoder, encryption_properties_interface& props, std::ostream& stream) |
@@ -51,7 +51,7 @@ class encryption_encoder_streambuf | ||
51 | 51 | _encryptionEncoder->init(stream, props); |
52 | 52 | |
53 | 53 | // set stream buffer |
54 | - this->setp(_encryptionEncoder->get_buffer_begin(), _encryptionEncoder->get_buffer_end() - 1); | |
54 | + this->setp(get_buffer_begin(), get_buffer_end() - 1); | |
55 | 55 | } |
56 | 56 | |
57 | 57 | bool is_init() const |
@@ -98,7 +98,17 @@ class encryption_encoder_streambuf | ||
98 | 98 | _encryptionEncoder->encrypt_next(inputLength); |
99 | 99 | |
100 | 100 | // set pointers for new buffer |
101 | - this->setp(_encryptionEncoder->get_buffer_begin(), _encryptionEncoder->get_buffer_end() - 1); | |
101 | + this->setp(get_buffer_begin(), get_buffer_end() - 1); | |
102 | + } | |
103 | + | |
104 | + char_type* get_buffer_begin() | |
105 | + { | |
106 | + return reinterpret_cast<char_type*>(_encryptionEncoder->get_buffer_begin()); | |
107 | + } | |
108 | + | |
109 | + char_type* get_buffer_end() | |
110 | + { | |
111 | + return reinterpret_cast<char_type*>(_encryptionEncoder->get_buffer_end()); | |
102 | 112 | } |
103 | 113 | |
104 | 114 | encryption_encoder_interface_ptr _encryptionEncoder; |
@@ -0,0 +1,18 @@ | ||
1 | +#pragma once | |
2 | +#include <iostream> | |
3 | +#include <vector> | |
4 | + | |
5 | +namespace utils { namespace stream { | |
6 | + | |
7 | +static void copy(std::istream& from, std::ostream& to, size_t bufferSize = 1024 * 1024) | |
8 | +{ | |
9 | + std::vector<char> buff(bufferSize); | |
10 | + | |
11 | + do | |
12 | + { | |
13 | + from.read(buff.data(), buff.size()); | |
14 | + to.write(buff.data(), from.gcount()); | |
15 | + } while (static_cast<size_t>(from.gcount()) == buff.size()); | |
16 | +} | |
17 | + | |
18 | +} } |
@@ -5,6 +5,8 @@ | ||
5 | 5 | #include <array> |
6 | 6 | #include <list> |
7 | 7 | |
8 | +namespace utils { namespace stream { | |
9 | + | |
8 | 10 | namespace detail { |
9 | 11 | |
10 | 12 | template <typename CONTAINER_TYPE> |
@@ -58,6 +60,20 @@ void serialize(std::basic_ostream<ELEM_TYPE, TRAITS_TYPE>& stream, const TYPE& v | ||
58 | 60 | } |
59 | 61 | |
60 | 62 | /** |
63 | + * \brief Serializes native array of the input type. | |
64 | + * | |
65 | + * \tparam TYPE Type of the value to be serialized. | |
66 | + * \tparam N Deducted array size. | |
67 | + * \param stream The stream to be serialized into. | |
68 | + * \param value The value to be serialized. | |
69 | + */ | |
70 | +template <typename TYPE, size_t N, typename ELEM_TYPE, typename TRAITS_TYPE> | |
71 | +void serialize(std::basic_ostream<ELEM_TYPE, TRAITS_TYPE>& stream, const TYPE(&value)[N]) | |
72 | +{ | |
73 | + stream.write(reinterpret_cast<const ELEM_TYPE*>(value), N * (sizeof(TYPE) / sizeof(ELEM_TYPE))); | |
74 | +} | |
75 | + | |
76 | +/** | |
61 | 77 | * \brief Serializes the input type of specified size |
62 | 78 | * |
63 | 79 | * \tparam TYPE Type of the value to be serialized. |
@@ -135,6 +151,23 @@ std::ios::pos_type deserialize(std::basic_istream<ELEM_TYPE, TRAITS_TYPE>& strea | ||
135 | 151 | } |
136 | 152 | |
137 | 153 | /** |
154 | + * \brief Deserializes native array of the input type. | |
155 | + * | |
156 | + * \tparam RETURN_TYPE Type of the value to be deserialized. | |
157 | + * \tparam N Deducted array size. | |
158 | + * \param stream The stream to be deserialized from. | |
159 | + * \param [out] out The deserialized value. | |
160 | + * | |
161 | + * \return Count of read elements. | |
162 | + */ | |
163 | +template <typename RETURN_TYPE, size_t N, typename ELEM_TYPE, typename TRAITS_TYPE> | |
164 | +std::ios::pos_type deserialize(std::basic_istream<ELEM_TYPE, TRAITS_TYPE>& stream, RETURN_TYPE(&out)[N]) | |
165 | +{ | |
166 | + stream.read(reinterpret_cast<ELEM_TYPE*>(out), N * sizeof(RETURN_TYPE)); | |
167 | + return stream.gcount(); | |
168 | +} | |
169 | + | |
170 | +/** | |
138 | 171 | * \brief Deserializes the input type from the stream |
139 | 172 | * |
140 | 173 | * \tparam RETURN_TYPE Type of the value to be deserialized. |
@@ -204,4 +237,6 @@ template <typename ELEM_TYPE, typename TRAITS_TYPE, typename ARRAY_ELEM_TYPE, si | ||
204 | 237 | std::ios::pos_type deserialize(std::basic_istream<ELEM_TYPE, TRAITS_TYPE>& stream, std::array<ARRAY_ELEM_TYPE, ARRAY_SIZE>& out) |
205 | 238 | { |
206 | 239 | return detail::deserialize_stl_container(stream, out, out.size()); |
207 | -} | |
\ No newline at end of file | ||
240 | +} | |
241 | + | |
242 | +} } |
@@ -1,18 +1,3 @@ | ||
1 | 1 | #pragma once |
2 | -#include <iostream> | |
3 | -#include <vector> | |
4 | - | |
5 | -namespace utils { namespace stream { | |
6 | - | |
7 | -static void copy(std::istream& from, std::ostream& to, size_t bufferSize = 1024 * 1024) | |
8 | -{ | |
9 | - std::vector<char> buff(bufferSize); | |
10 | - | |
11 | - do | |
12 | - { | |
13 | - from.read(buff.data(), buff.size()); | |
14 | - to.write(buff.data(), from.gcount()); | |
15 | - } while (static_cast<size_t>(from.gcount()) == buff.size()); | |
16 | -} | |
17 | - | |
18 | -} } | |
2 | +#include "stream/copy.h" | |
3 | +#include "stream/serialization.h" |