stockpiles: remove dependency on full protobuf

develop
Casey Link 2014-11-27 14:23:54 +01:00
parent de919050b1
commit d352d0f42d
1 changed files with 13 additions and 39 deletions

@ -41,7 +41,6 @@
// protobuf // protobuf
#include "proto/stockpiles.pb.h" #include "proto/stockpiles.pb.h"
#include <google/protobuf/text_format.h>
// os // os
#include <sys/stat.h> #include <sys/stat.h>
@ -476,20 +475,6 @@ public:
return mBuffer.SerializeToOstream ( &output ); return mBuffer.SerializeToOstream ( &output );
} }
/**
* Serializes the stockpile settings to a string.
* @return empty string on error
*/
std::string serialize_to_string()
{
mBuffer.Clear();
write();
std::string str;
if ( !TextFormat::PrintToString ( mBuffer, &str ) )
return std::string();
return str;
}
/** /**
* Read stockpile settings from file * Read stockpile settings from file
*/ */
@ -502,15 +487,6 @@ public:
return res; return res;
} }
/**
* Read text_format stockpile settings from string
*/
bool unserialize_from_string ( const std::string & data )
{
mBuffer.Clear();
return TextFormat::ParseFromString ( data, &mBuffer );
}
private: private:
bool mDebug; bool mDebug;
@ -2762,24 +2738,22 @@ static command_result savestock ( color_ostream &out, vector <string> & paramete
file = o; file = o;
} }
} }
if ( file.empty() )
{
out.printerr("You must supply a valid filename.\n");
return CR_WRONG_USAGE;
}
StockpileSerializer cereal ( sp ); StockpileSerializer cereal ( sp );
if ( debug ) if ( debug )
cereal.enable_debug ( out ); cereal.enable_debug ( out );
if ( file.empty() )
{
std::string data = cereal.serialize_to_string();
out << data << endl;
}
else
{
if ( !is_dfstockfile ( file ) ) file += ".dfstock"; if ( !is_dfstockfile ( file ) ) file += ".dfstock";
if ( !cereal.serialize_to_file ( file ) ) if ( !cereal.serialize_to_file ( file ) )
{ {
out.printerr ( "serialize failed\n" ); out.printerr ( "serialize failed\n" );
return CR_FAILURE; return CR_FAILURE;
} }
}
return CR_OK; return CR_OK;
} }