bool BaseVariantProtocol::SignalInputData(IOBuffer &buffer) { if (_pProtocolHandler == NULL) { FATAL("This protocol is not registered to any application yet"); return false; } if (_pFarProtocol->GetType() == PT_OUTBOUND_HTTP || _pFarProtocol->GetType() == PT_INBOUND_HTTP) { #ifdef HAS_PROTOCOL_HTTP //1. This is a HTTP based transfer. We only start doing stuff //after a complete request is made. BaseHTTPProtocol *pHTTPProtocol = (BaseHTTPProtocol *) _pFarProtocol; if (!pHTTPProtocol->TransferCompleted()) return true; if (!Deserialize(GETIBPOINTER(buffer), pHTTPProtocol->GetContentLength(), _lastReceived)) { FATAL("Unable to deserialize content"); return false; } buffer.Ignore(pHTTPProtocol->GetContentLength()); _lastReceived.Compact(); return _pProtocolHandler->ProcessMessage(this, _lastSent, _lastReceived); #else FATAL("HTTP protocol not supported"); return false; #endif /* HAS_PROTOCOL_HTTP */ } else if (_pFarProtocol->GetType() == PT_TCP) { while (GETAVAILABLEBYTESCOUNT(buffer) > 4) { uint32_t size = ENTOHLP(GETIBPOINTER(buffer)); if (size > 4 * 1024 * 1024) { FATAL("Size too big: %u", size); return false; } if (GETAVAILABLEBYTESCOUNT(buffer) < size + 4) { FINEST("Need more data"); return true; } if (!Deserialize(GETIBPOINTER(buffer) + 4, size, _lastReceived)) { FATAL("Unable to deserialize variant"); return false; } buffer.Ignore(size + 4); _lastReceived.Compact(); if (!_pProtocolHandler->ProcessMessage(this, _lastSent, _lastReceived)) { FATAL("Unable to process message"); return false; } } return true; } else { FATAL("Invalid protocol stack"); return false; } }
void CombatData::load(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(m_combat_turn_number) & BOOST_SERIALIZATION_NVP(m_system); Deserialize(ar, m_combat_universe); PathingEngine::s_combat_universe = &m_combat_universe; Deserialize(ar, m_pathing_engine); PathingEngine::s_combat_universe = 0; }
bool Deserialize(const rapidjson::Value& json_val, jos_lib::SyncServerConf& obj_val) { do { // fields from "jos_lib::SyncServerConf" if (!Deserialize(json_val, "network", obj_val.network, obj_val.json_has_network)) break; // @(field_type : NetworkConf) if (!Deserialize(json_val, "sync", obj_val.sync, obj_val.json_has_sync)) break; // @(field_type : SyncConf) return true; } while (0); return false; }
Simple *DeserializeSimple(const uint8_t *data, int dataLen, bool *usedDefaultOut) { void *res = NULL; res = Deserialize(data, dataLen, SimpleVersion, &gSimpleMetadata); if (res) { *usedDefaultOut = false; return (Simple*)res; } res = Deserialize(&gSimpleDefault[0], sizeof(gSimpleDefault), SimpleVersion, &gSimpleMetadata); CrashAlwaysIf(!res); *usedDefaultOut = true; return (Simple*)res; }
bool Deserialize ( const Json::Value& json_val, json_lib::Status& obj_val ) { do { // fields from "json_lib::Status" if ( ! Deserialize (json_val, "total_status", obj_val.total_status, obj_val.json_has_total_status) ) break; // @(field_type : std::map<std::string, uint64_t>) if ( ! Deserialize (json_val, "status", obj_val.status, obj_val.json_has_status) ) break; // @(field_type : std::map<std::string, std::map<std::string, uint64_t> >) return true; } while ( 0 ); return false; }
bool CSettingsManager::Load(const TiXmlElement *root, bool &updated, bool triggerEvents /* = true */, std::map<std::string, CSetting*> *loadedSettings /* = NULL */) { CSharedLock lock(m_critical); CExclusiveLock settingsLock(m_settingsCritical); if (m_loaded || root == NULL) return false; if (triggerEvents && !OnSettingsLoading()) return false; if (!Deserialize(root, loadedSettings)) return false; bool ret = true; // load any ISubSettings implementations if (triggerEvents) ret = Load(root); updated = UpdateSettings(root); if (triggerEvents) OnSettingsLoaded(); return ret; }
bool Application::Initialize(const std::string& configDataPath, OPTIONAL HINSTANCE appInstanceHandler) { this->_SetResourcesPath(); this->_configDataPath = configDataPath; auto logger = Logger::Create(); if (false == Deserialize(ExtendString::Format("%s\\%s", _resourcesPath.c_str(), _configDataPath.c_str()).c_str())) { LOG_ERROR("Failed to deserialize a Application"); return false; } _isReplaceData = true; if (false == _CreateWindow((nullptr == appInstanceHandler) ? GetModuleHandle(nullptr) : appInstanceHandler)) { LOG_ERROR("Failed to create a WinAPI"); return false; } auto director = Director::Create(); if (false == director->Initialize(_winHandler)) { LOG_ERROR("Failed to initialize a Director"); director->Destroy(); return false; } return _OnInitialize(); }
void CPlayer::Deserialize(std::string jsonstr) { rapidjson::Document attrs; attrs.Parse<0>(jsonstr.c_str()); Deserialize(attrs); }
ezResult ezTextureAtlasCreationDesc::Load(const char* szFile) { ezFileReader file; EZ_SUCCEED_OR_RETURN(file.Open(szFile)); return Deserialize(file); }
void Deserialize_Array( const Json::Value& srcValue, const mxArrayType& arrayInfo, void *rawMem ) { Assert( srcValue.isArray() ); const UINT numObjects = srcValue.size(); arrayInfo.Generic_Set_Count( rawMem, numObjects ); const void* pArrayData = arrayInfo.Generic_Get_Data( rawMem ); const mxType& itemType = arrayInfo.m_elemType; const UINT itemSize = itemType.m_instanceSize; for( Json::Value::UInt iObject = 0; iObject < numObjects; iObject++ ) { void* pObject = (BYTE*)pArrayData + iObject * itemSize; const Json::Value objectValue = srcValue[ iObject ]; Deserialize( objectValue, itemType, pObject, 0/*offset*/ ); } }
ObstacleSpawner::ObstacleSpawner(GameActor* player) { Deserialize(); _nextpos.x = player->GetPosition().x+2*player->GetCenter().x; _nextpos.y = player->GetPosition().y+2*player->GetCenter().y; /* TODO: This part should be in the tick generate the obstactle base On It's weight and the hard of the level stage Now just random generate some obstacle for test; */ for (int i = 0; i < 100; i++) { _nextpos.x+=Random(100,150); int j= Random(4,1); GenerateObstacle(_nextpos,j-1); } }
Node* Node::Deserialize(const YAML::Node& node) { Node* n = new Node; std::string uuid; node["uuid"] >> uuid; std::cout << "::LOADING " << uuid << std::endl; n->mId = boost::uuids::string_generator()(uuid); try { for(unsigned i = 0; i < node["children"].size(); i++) { Node* c = Deserialize(node["children"][i]); if(c != nullptr) n->AddChild(c); } } catch(YAML::TypedKeyNotFound<std::string> e) {} try { for(unsigned i = 0; i < node["components"].size(); i++) { Component* c = Component::Deserialize(node["components"][i]); if(c != nullptr) n->AddComponent(c); } } catch(YAML::TypedKeyNotFound<std::string> e) {} return n; }
bool StreamCapabilities::Deserialize(string seekFilePath, StreamCapabilities &capabilities) { File file; if (!file.Initialize(seekFilePath, FILE_OPEN_MODE_READ)) { FATAL("Unable to open seek file %s", STR(seekFilePath)); return false; } uint32_t length = 0; if (!file.ReadUI32(&length, false)) { FATAL("Unable to read stream capabilities length from file %s", STR(seekFilePath)); return false; } if (length > 1024 * 1024) { FATAL("Invalid stream capabilities length in file %s: %"PRIu32, STR(seekFilePath), length); return false; } IOBuffer buffer; buffer.ReadFromRepeat(0, length); if (!file.ReadBuffer(GETIBPOINTER(buffer), length)) { FATAL("Unable to read stream capabilities payload from file %s", STR(seekFilePath)); return false; } file.Close(); if (!Deserialize(buffer, capabilities)) { FATAL("Unable to deserialize stream capabilities from file %s", STR(seekFilePath)); return false; } return true; }
/// Loads a Power Tab object from an input stream /// @param stream Input stream to load from /// @param version File version /// @return True if the object was loaded, false if not bool PowerTabObject::Deserialize(wxInputStream& stream, wxWord version) { //------Last Checked------// // - Dec 21, 2004 PowerTabInputStream data_stream(stream); return (Deserialize(data_stream, version)); }
bool SystemAddressList::Load(const char *filename) { FILE *fp = NULL; unsigned long fileSize; if ( ( fp = fopen( filename, "rb" ) ) == 0 ) return false; fseek( fp, 0, SEEK_END ); fileSize = ftell( fp ); fseek( fp, 0, SEEK_SET ); if (fileSize==0) { fclose(fp); return false; } unsigned char *filedata = (unsigned char*) rakMalloc_Ex( fileSize, __FILE__, __LINE__ ); fread(filedata, fileSize, 1, fp); fclose(fp); RakNet::BitStream bs(filedata, fileSize, false); Deserialize(&bs); rakFree_Ex(filedata, __FILE__, __LINE__ ); return true; }
bool DeserializeRawPacket(Blam::BitStream *stream, int packetSize, void *packet) override { // Verify the packet size and typecast to the type-safe packet data if (packetSize != sizeof(Packet<TData>)) return false; auto fullPacket = static_cast<Packet<TData>*>(packet); return Deserialize(stream, &fullPacket->Data); }
bool VolumeHeader::Decrypt (const ConstBufferPtr &encryptedData, const VolumePassword &password, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes) { if (password.Size() < 1) throw PasswordEmpty (SRC_POS); ConstBufferPtr salt (encryptedData.GetRange (SaltOffset, SaltSize)); SecureBuffer header (EncryptedHeaderDataSize); SecureBuffer headerKey (GetLargestSerializedKeySize()); foreach (shared_ptr <Pkcs5Kdf> pkcs5, keyDerivationFunctions) { pkcs5->DeriveKey (headerKey, password, salt); foreach (shared_ptr <EncryptionMode> mode, encryptionModes) { if (typeid (*mode) != typeid (EncryptionModeXTS)) mode->SetKey (headerKey.GetRange (0, mode->GetKeySize())); foreach (shared_ptr <EncryptionAlgorithm> ea, encryptionAlgorithms) { if (!ea->IsModeSupported (mode)) continue; /* printf("trying %ls, %ls, %ls\n", pkcs5->GetName().c_str(), mode->GetName().c_str(), ea->GetName().c_str() ); */ if (typeid (*mode) == typeid (EncryptionModeXTS)) { ea->SetKey (headerKey.GetRange (0, ea->GetKeySize())); mode = mode->GetNew(); mode->SetKey (headerKey.GetRange (ea->GetKeySize(), ea->GetKeySize())); } else { ea->SetKey (headerKey.GetRange (LegacyEncryptionModeKeyAreaSize, ea->GetKeySize())); } ea->SetMode (mode); header.CopyFrom (encryptedData.GetRange (EncryptedHeaderDataOffset, EncryptedHeaderDataSize)); ea->Decrypt (header); if (Deserialize (header, ea, mode)) { EA = ea; Pkcs5 = pkcs5; return true; } } } }
bool Deserialize ( const Json::Value& json_val, unsigned short& obj_val ) { unsigned int tmp_obj_val = 0; if ( ! Deserialize (json_val, tmp_obj_val) ) { return false; } obj_val = static_cast < unsigned short > ( tmp_obj_val ); return true; }
GlobalGameSettings& GlobalGameSettings::operator=(const GlobalGameSettings& ggs) { if(this == &ggs) return *this; Serializer ser; ggs.Serialize(ser); Deserialize(ser); return *this; }
bool Deserialize ( const Json::Value& json_val, char& obj_val ) { int tmp_obj_val = 0; if ( ! Deserialize (json_val, tmp_obj_val) ) { return false; } obj_val = static_cast < char > ( tmp_obj_val ); return true; }
Message::Message( char *jsonString ) { // Intialize a blank message so that if this class is written to JSON, it will be a full message InitializeBlankMessage(); // If a JSON string was passed in, fill out the MessageData if( jsonString != 0 ) Deserialize( _MessageData, jsonString ); _JsonString = jsonString; }
void PhysicalPathDoneEventPackage::Get(unsigned sourceRank, unsigned messageTag, ICommunicator *comm) { //comm = new Communicator(); if (comm != NULL) { comm->GetPacked(PhysicalPathDoneEventPackageBufSize*DoubleSize, CommType::ASynch, sourceRank, messageTag, &myBuffer); } Deserialize(comm); }
bool Open(wchar_t *path) { Stream stream(path, false); if(!stream.IsValid()) { return false; } Deserialize(stream); return true; }
inline void mmImages::DeserializeParameters(mmString const & p_sSerializedParams, std::list<mmGenericParamI*> & p_sParams) { std::auto_ptr<mmXML::mmXMLDocI> v_psXML(mmInterfaceInitializers::CreateXMLDocument()); v_psXML->ParseXMLBuffer(p_sSerializedParams); std::vector<mmXML::mmXMLNodeI*> v_sChildNodes = v_psXML->GetXMLRootNode()->GetChildren(); std::list<mmGenericParamI*>::iterator v_sParam; mmXML::mmXMLNodeI* v_psNameNode; for(std::size_t v_iI = 0; v_iI < v_sChildNodes.size(); ++v_iI) { if((v_psNameNode = v_sChildNodes[v_iI]->FindChild(g_pAutoCalcXML_Params_ParamName_Node)) != NULL && (v_sParam = std::find_if(p_sParams.begin(), p_sParams.end(), mmGenericParamI::FindByName(v_psNameNode->GetText()))) != p_sParams.end()) Deserialize(v_sChildNodes[v_iI], *v_sParam); } }
// CONSTRUCTOR //------------------------------------------------------------------------------ Job::Job( IOStream & stream ) : m_Node( nullptr ) , m_Data( nullptr ) , m_DataSize( 0 ) , m_UserData( nullptr ) , m_IsLocal( false ) , m_SystemErrorCount( 0 ) , m_ToolManifest( nullptr ) { Deserialize( stream ); }
void LoadGame(const std::string& filename, ServerSaveGameData& server_save_game_data, std::vector<PlayerSaveGameData>& player_save_game_data, Universe& universe, EmpireManager& empire_manager, SpeciesManager& species_manager, CombatLogManager& combat_log_manager) { //Sleep(5000); // player notifications if (ServerApp* server = ServerApp::GetApp()) server->Networking().SendMessage(TurnProgressMessage(Message::LOADING_GAME)); GetUniverse().EncodingEmpire() = ALL_EMPIRES; std::map<int, SaveGameEmpireData> ignored_save_game_empire_data; empire_manager.Clear(); universe.Clear(); try { #ifdef FREEORION_WIN32 // convert UTF-8 file name to UTF-16 fs::path::string_type file_name_native; utf8::utf8to16(filename.begin(), filename.end(), std::back_inserter(file_name_native)); fs::path path = fs::path(file_name_native); #else fs::path path = fs::path(filename); #endif fs::ifstream ifs(path, std::ios_base::binary); if (!ifs) throw std::runtime_error(UNABLE_TO_OPEN_FILE); FREEORION_IARCHIVE_TYPE ia(ifs); Logger().debugStream() << "LoadGame : Reading Server Save Game Data"; ia >> BOOST_SERIALIZATION_NVP(server_save_game_data); Logger().debugStream() << "LoadGame : Reading Player Save Game Data"; ia >> BOOST_SERIALIZATION_NVP(player_save_game_data); Logger().debugStream() << "LoadGame : Reading Empire Save Game Data (Ignored)"; ia >> BOOST_SERIALIZATION_NVP(ignored_save_game_empire_data); Logger().debugStream() << "LoadGame : Reading Empires Data"; ia >> BOOST_SERIALIZATION_NVP(empire_manager); Logger().debugStream() << "LoadGame : Reading Species Data"; ia >> BOOST_SERIALIZATION_NVP(species_manager); Logger().debugStream() << "LoadGame : Reading Combat Logs"; ia >> BOOST_SERIALIZATION_NVP(combat_log_manager); Logger().debugStream() << "LoadGame : Reading Universe Data"; Deserialize(ia, universe); } catch (const std::exception& e) { Logger().errorStream() << UserString("UNABLE_TO_READ_SAVE_FILE") << " LoadGame exception: " << ": " << e.what(); throw e; } Logger().debugStream() << "LoadGame : Done loading save file"; }
PDC::Robot* RobotPersistence::Load(const std::string& filename) { std::ifstream file(filename.c_str()); std::stringstream buffer; buffer << file.rdbuf(); file.close(); std::string json = buffer.str(); PDC::Robot* robot; Deserialize(json,&robot); return robot; }
int NaClDeserializeNaClDescMetadata( const uint8_t *buffer, uint32_t buffer_length, struct NaClRichFileInfo *info) { /* Work around const issues. */ char *file_path = NULL; uint32_t offset = 0; NaClRichFileInfoCtor(info); if (Deserialize(buffer, buffer_length, &info->known_file, sizeof(info->known_file), &offset)) goto on_error; if (info->known_file) { if (Deserialize(buffer, buffer_length, &info->file_path_length, sizeof(info->file_path_length), &offset)) goto on_error; file_path = malloc(info->file_path_length); if (NULL == file_path) goto on_error; if (Deserialize(buffer, buffer_length, file_path, info->file_path_length, &offset)) goto on_error; info->file_path = file_path; file_path = NULL; } /* Entire buffer consumed? */ if (offset != buffer_length) goto on_error; return 0; on_error: free(file_path); NaClRichFileInfoDtor(info); return 1; }
int main( ) { FILE* fp = fopen( "out.txt", "w" ); A a; B b; C c; a.a = 1; a.b = 10; b.a = 2; b.b = 20.0f; b.c = "twenty point zero f"; c.a = 3; c.b.a = 4; c.b.b = 5; Serialize( fp, a ); Serialize( fp, b ); Serialize( fp, c ); memset( &a, 0, sizeof( a ) ); memset( &b, 0, sizeof( b ) ); memset( &c, 0, sizeof( c ) ); fclose( fp ); fp = fopen( "out.txt", "r" ); Deserialize( fp, a ); Deserialize( fp, b ); Deserialize( fp, c ); fclose( fp ); return 0; }
bool PokerHandHistory::Load(LongBinary* pBin){ if( !pBin || pBin->GetBinarySize() == 0 ) return false; void* lpBuffer = pBin->LockMemory(); if( !lpBuffer ) return false; GrowableMemory mem(0, 0, false); mem.SetReadonlyBuffer((BYTE*)lpBuffer, (int)pBin->GetBinarySize()); // Clear history info. ClearHistory(); // Deserialize. bool bRet = (Deserialize(&mem) == TRUE); pBin->UnlockMemory(); return bRet; }