mirror of
https://github.com/fraillt/bitsery.git
synced 2026-06-08 08:13:56 +00:00
compile warnings, and usage improvements for VisualStudio
This commit is contained in:
@@ -27,6 +27,12 @@ include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
file(GLOB ExampleFiles ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
|
||||
if (WIN32)
|
||||
message(WARNING "Removing example `flexible_assert_linux_x64` for Windows")
|
||||
list(REMOVE_ITEM ExampleFiles ${CMAKE_CURRENT_SOURCE_DIR}/flexible_assert_linux_x64.cpp)
|
||||
endif()
|
||||
|
||||
|
||||
FOREACH(ExampleFile ${ExampleFiles})
|
||||
get_filename_component(ExampleName ${ExampleFile} NAME_WE)
|
||||
add_executable(${ExampleName} ${ExampleFile})
|
||||
|
||||
@@ -20,7 +20,7 @@ void serialize(S& s, MyStruct& o) {
|
||||
s.value4b(o.i);//fundamental types (ints, floats, enums) of size 4b
|
||||
s.value2b(o.e);
|
||||
s.container4b(o.fs, 10);//resizable containers also requires maxSize, to make it safe from buffer-overflow attacks
|
||||
};
|
||||
}
|
||||
|
||||
using namespace bitsery;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ int main() {
|
||||
Buffer buffer{};
|
||||
auto writtenSize = quickSerialization<OutputAdapter>(buffer, data);
|
||||
|
||||
MyTypes::Monster res;
|
||||
MyTypes::Monster res{};
|
||||
auto state = quickDeserialization<InputAdapter>({buffer.begin(), writtenSize}, res);
|
||||
|
||||
assert(state.first == ReaderError::NoError && state.second);
|
||||
|
||||
@@ -15,9 +15,13 @@ struct GameMode {
|
||||
namespace MyTypes {
|
||||
|
||||
struct Monster {
|
||||
std::string name;
|
||||
uint32_t minDamage;
|
||||
uint32_t maxDamage;
|
||||
Monster() = default;
|
||||
Monster(std::string _name, uint32_t minDmg, uint32_t maxDmg)
|
||||
:name{_name}, minDamage{minDmg}, maxDamage{maxDmg} {}
|
||||
|
||||
std::string name{};
|
||||
uint32_t minDamage{};
|
||||
uint32_t maxDamage{};
|
||||
//...
|
||||
};
|
||||
|
||||
@@ -81,7 +85,7 @@ int main() {
|
||||
w.flush();
|
||||
auto writtenSize = w.writtenBytesCount();
|
||||
|
||||
MyTypes::GameState res;
|
||||
MyTypes::GameState res{};
|
||||
Deserializer <InputAdapter> des { InputAdapter{buffer.begin(), writtenSize}, &mode};
|
||||
des.object(res);
|
||||
auto& r = AdapterAccess::getReader(des);
|
||||
|
||||
@@ -17,7 +17,7 @@ void serialize(S& s, MyStruct& o) {
|
||||
s.value4b(o.i);
|
||||
s.value2b(o.e);
|
||||
s.value8b(o.f);
|
||||
};
|
||||
}
|
||||
|
||||
using namespace bitsery;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ struct MyStruct {
|
||||
//now we can use flexible syntax with
|
||||
//member function has same name as parameter
|
||||
s.archive(this->s, i, vl, ll);
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ struct MyStruct {
|
||||
void serialize(S& s) {
|
||||
//now we can use flexible syntax with
|
||||
s.archive(i, e, fs);
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -15,8 +15,10 @@ namespace MyTypes {
|
||||
struct Vec3 { float x, y, z; };
|
||||
|
||||
struct Weapon {
|
||||
std::string name;
|
||||
int16_t damage;
|
||||
std::string name{};
|
||||
int16_t damage{};
|
||||
Weapon() = default;
|
||||
Weapon(const std::string& _name, int16_t dmg):name{_name}, damage{dmg} {}
|
||||
private:
|
||||
//define serialize function as private, and give access to bitsery
|
||||
friend bitsery::Access;
|
||||
|
||||
Reference in New Issue
Block a user