itsNextName properly initialized to nullptr for json output

This commit is contained in:
Shane Grant
2013-07-09 10:32:50 -07:00
parent cc8784660c
commit 525341a9d8
2 changed files with 15 additions and 39 deletions

View File

@@ -66,7 +66,8 @@ namespace cereal
JSONOutputArchive(std::ostream & stream, int precision = 20) : JSONOutputArchive(std::ostream & stream, int precision = 20) :
OutputArchive<JSONOutputArchive>(this), OutputArchive<JSONOutputArchive>(this),
itsWriteStream(stream), itsWriteStream(stream),
itsWriter(itsWriteStream, precision) itsWriter(itsWriteStream, precision),
itsNextName(nullptr)
{ {
itsNameCounter.push(0); itsNameCounter.push(0);
itsNodeStack.push(NodeType::StartObject); itsNodeStack.push(NodeType::StartObject);
@@ -315,8 +316,8 @@ namespace cereal
std::memcpy( &val, decoded.data(), decoded.size() ); std::memcpy( &val, decoded.data(), decoded.size() );
} }
//! Loads some binary data, encoded as a base64 string, with an optional name //! Loads some binary data, encoded as a base64 string
void loadBinaryValue( void * data, size_t size, char const * name = nullptr) void loadBinaryValue( void * data, size_t size )
{ {
startNode(); startNode();

View File

@@ -242,20 +242,10 @@ int main()
std::ofstream os("file.json"); std::ofstream os("file.json");
cereal::JSONOutputArchive oar( os ); cereal::JSONOutputArchive oar( os );
//std::vector<int> x = {1, 2, 3, 4, 5}; int arr[] = {-1, 3, 999};
std::multimap<float, AAA> x; oar( 5 );
x.insert( std::make_pair(.9999999, AAA()) ); oar.saveBinaryValue( arr, sizeof(int)*3, "cool beans" );
x.insert( std::make_pair(.9999999, AAA()) ); oar.saveBinaryValue( arr, sizeof(int)*3 );
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;
}
} }
{ {
@@ -268,29 +258,14 @@ int main()
std::ifstream is("file.json"); std::ifstream is("file.json");
cereal::JSONInputArchive iar( is ); cereal::JSONInputArchive iar( is );
std::multimap<float, AAA> x; int arr[3];
int x;
iar( CEREAL_NVP(x) ); iar( x );
iar.loadBinaryValue( arr, sizeof(int) * 3 );
for(auto i : x) assert( arr[0] == -1 );
{ assert( arr[1] == 3 );
std::cout << i.first << std::endl; assert( arr[2] == 999 );
std::cout << i.second.one << std::endl;
std::cout << i.second.two << std::endl;
std::cout << std::endl;
}
} }
//{
// 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; return 0;
} }