Skip to content

Commit 65f7879

Browse files
committed
arr
1 parent a4a96b5 commit 65f7879

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

CoreLib.Serialization/DataSerializer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,18 @@ namespace JxCoreLib::Serialization
8888

8989
return stream;
9090
}
91+
92+
template<typename T, int N>
93+
Stream& ReadWriteStream(Stream& stream, bool is_write, std::array<T, N>& arr)
94+
{
95+
int32_t len = arr.size();
96+
ReadWriteStream(stream, is_write, len);
97+
for (int i = 0; i < len; i++)
98+
{
99+
ReadWriteStream(stream, is_write, arr[i]);
100+
}
101+
102+
return stream;
103+
}
104+
91105
}

Example/TestFile.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <CoreLib/File.h>
22
#include <cassert>
33
#include <string>
4+
#include <array>
45
#include <CoreLib.Serialization/DataSerializer.h>
56

67
using namespace JxCoreLib;
@@ -31,6 +32,9 @@ void TestFile()
3132
std::vector<int> arr = { 2,3,4,8 };
3233
ReadWriteStream(fs, is_ser, arr);
3334

35+
std::array<int, 3> ar = { 1 };
36+
ReadWriteStream(fs, is_ser, ar);
37+
3438
int32_t oi32;
3539
string ostr;
3640
fs.set_position(0);
@@ -40,9 +44,13 @@ void TestFile()
4044
std::vector<int> oarr;
4145
ReadWriteStream(fs, !is_ser, oarr);
4246

47+
std::array<int, 3> oar;
48+
ReadWriteStream(fs, !is_ser, oar);
49+
4350
assert(oi32 == i32);
4451
assert(str == ostr);
4552
assert(arr == oarr);
53+
assert(!memcmp(ar.data(), oar.data(), ar.size()));
4654
}
4755
{
4856
FileStream fs{ "D:/a.txt", FileOpenMode::Read };

0 commit comments

Comments
 (0)