diff --git a/include/cereal/archives/json.hpp b/include/cereal/archives/json.hpp index 6f69a8d4..8f30dfc7 100644 --- a/include/cereal/archives/json.hpp +++ b/include/cereal/archives/json.hpp @@ -66,7 +66,8 @@ namespace cereal JSONOutputArchive(std::ostream & stream, int precision = 20) : OutputArchive(this), itsWriteStream(stream), - itsWriter(itsWriteStream, precision) + itsWriter(itsWriteStream, precision), + itsNextName(nullptr) { itsNameCounter.push(0); itsNodeStack.push(NodeType::StartObject); @@ -315,8 +316,8 @@ namespace cereal std::memcpy( &val, decoded.data(), decoded.size() ); } - //! Loads some binary data, encoded as a base64 string, with an optional name - void loadBinaryValue( void * data, size_t size, char const * name = nullptr) + //! Loads some binary data, encoded as a base64 string + void loadBinaryValue( void * data, size_t size ) { startNode(); diff --git a/sandbox_json.cpp b/sandbox_json.cpp index 84a343d4..da855e43 100644 --- a/sandbox_json.cpp +++ b/sandbox_json.cpp @@ -242,20 +242,10 @@ int main() std::ofstream os("file.json"); cereal::JSONOutputArchive oar( os ); - //std::vector x = {1, 2, 3, 4, 5}; - std::multimap x; - x.insert( std::make_pair(.9999999, AAA()) ); - x.insert( std::make_pair(.9999999, AAA()) ); - - oar( CEREAL_NVP(x) ); - - for(auto i : x) - { - std::cout << i.first << std::endl; - std::cout << i.second.one << std::endl; - std::cout << i.second.two << std::endl; - std::cout << std::endl; - } + int arr[] = {-1, 3, 999}; + oar( 5 ); + oar.saveBinaryValue( arr, sizeof(int)*3, "cool beans" ); + oar.saveBinaryValue( arr, sizeof(int)*3 ); } { @@ -268,29 +258,14 @@ int main() std::ifstream is("file.json"); cereal::JSONInputArchive iar( is ); - std::multimap x; - - iar( CEREAL_NVP(x) ); - - for(auto i : x) - { - std::cout << i.first << std::endl; - std::cout << i.second.one << std::endl; - std::cout << i.second.two << std::endl; - std::cout << std::endl; - } - + int arr[3]; + int x; + iar( x ); + iar.loadBinaryValue( arr, sizeof(int) * 3 ); + assert( arr[0] == -1 ); + assert( arr[1] == 3 ); + assert( arr[2] == 999 ); } - //{ - // std::ifstream is("file.json"); - // rapidjson::GenericReadStream stream(is); - // rapidjson::Document doc; - // doc.ParseStream<0>(stream); - - // auto x = doc.MemberBegin(); - // std::cout << x->name.GetString() << std::endl; - // std::cout << x->value.IsArray() << std::endl; - //} return 0; }