load binary working properly, everything looks good for json

This commit is contained in:
Shane Grant
2013-07-09 10:46:13 -07:00
parent 525341a9d8
commit 048c00a92f
2 changed files with 38 additions and 22 deletions

View File

@@ -229,6 +229,15 @@ namespace cereal
return *this; return *this;
} }
GenericValue const & name()
{
switch(itsType)
{
case Member: return itsMemberIt->name;
default: throw cereal::Exception("Invalid Iterator Type!");
}
}
GenericValue const & value() GenericValue const & value()
{ {
switch(itsType) switch(itsType)
@@ -319,8 +328,6 @@ namespace cereal
//! Loads some binary data, encoded as a base64 string //! Loads some binary data, encoded as a base64 string
void loadBinaryValue( void * data, size_t size ) void loadBinaryValue( void * data, size_t size )
{ {
startNode();
std::string encoded; std::string encoded;
loadValue( encoded ); loadValue( encoded );
auto decoded = base64::decode( encoded ); auto decoded = base64::decode( encoded );
@@ -329,8 +336,6 @@ namespace cereal
throw Exception("Decoded binary data size does not match specified size"); throw Exception("Decoded binary data size does not match specified size");
std::memcpy( data, decoded.data(), decoded.size() ); std::memcpy( data, decoded.data(), decoded.size() );
finishNode();
}; };
void loadSize(size_t & size) void loadSize(size_t & size)

View File

@@ -202,13 +202,25 @@ struct SubFixture
struct Fixture struct Fixture
{ {
SubFixture f1, f2, f3; SubFixture f1, f2, f3;
template<class Archive> int array[4] = {1, 2, 3, 4};
void serialize(Archive & ar)
{ template<class Archive>
ar( f1, void save(Archive & ar) const
CEREAL_NVP(f2), {
f3 ); ar( f1,
} CEREAL_NVP(f2),
f3 );
ar.saveBinaryValue( array, sizeof(int)*4, "cool array man" );
}
template<class Archive>
void load(Archive & ar)
{
ar( f1,
CEREAL_NVP(f2),
f3 );
ar.loadBinaryValue( array, sizeof(int)*4 );
}
void change() void change()
{ {
@@ -242,10 +254,10 @@ int main()
std::ofstream os("file.json"); std::ofstream os("file.json");
cereal::JSONOutputArchive oar( os ); cereal::JSONOutputArchive oar( os );
int arr[] = {-1, 3, 999}; auto f = std::make_shared<Fixture>();
oar( 5 ); auto f2 = f;
oar.saveBinaryValue( arr, sizeof(int)*3, "cool beans" ); oar( f );
oar.saveBinaryValue( arr, sizeof(int)*3 ); oar( f2 );
} }
{ {
@@ -258,13 +270,12 @@ int main()
std::ifstream is("file.json"); std::ifstream is("file.json");
cereal::JSONInputArchive iar( is ); cereal::JSONInputArchive iar( is );
int arr[3]; std::shared_ptr<Fixture> f, f2;
int x; iar( f, f2 );
iar( x ); assert( f->array[0] == 1 );
iar.loadBinaryValue( arr, sizeof(int) * 3 ); assert( f->array[1] == 2 );
assert( arr[0] == -1 ); assert( f->array[2] == 3 );
assert( arr[1] == 3 ); assert( f->array[3] == 4 );
assert( arr[2] == 999 );
} }
return 0; return 0;