#include "schema.h" #include "rapidjson\rapidjson.h" #include "rapidjson\document.h" #include "rapidjson\writer.h" #include "rapidjson\stringbuffer.h" namespace schema{ namespace serializor { namespace { template static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const char v[]); template static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const std::string& v); template static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const T& v); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_RECT_FIELD& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const std::vector& schema_elements); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_QUESTION& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_ELEMENT_FIELD& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_KEGUANTI& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOCATE_POINT& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOCATE_AREA& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOACTE_CROSS& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_TIANTUKAOHAO& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_QUEKAOBIAOJI& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_ABJUANBIAOJI& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_XUANZUOTI& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_CODE& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_CLIP& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_PAGE& schema_element); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const SCHEMA_VERSION& version); template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const SCHEMA& schema_element); static inline void deserialize(float&dst, const rapidjson::Value &json); static inline void deserialize(double&dst, const rapidjson::Value &json); static inline void deserialize(bool&dst, const rapidjson::Value &json); static inline void deserialize(int&dst, const rapidjson::Value &json); static inline void deserialize(char dst[], const rapidjson::Value &json); static inline void deserialize(std::string & dst, const rapidjson::Value &json); templatestatic inline void deserialize(T&dst, const rapidjson::Value &json); templatestatic inline void deserialize(T dst[], int& count, int group_size[], int& group_count, const rapidjson::Value &json); templatestatic inline void deserialize(T dst[], int& count, const rapidjson::Value &json); templatestatic bool deserialize(const rapidjson::Value &json, SCHEMA_RECT_FIELD &schema_element); templatestatic bool deserialize(std::vector &schema_elements, const rapidjson::Value &json); static bool deserialize(const rapidjson::Value &json, SCHEMA_ELEMENT_FIELD &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_CLIP &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_CODE &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_KEGUANTI &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_LOCATE_AREA &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_LOACTE_CROSS &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_LOCATE_POINT &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_QUEKAOBIAOJI &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_TIANTUKAOHAO &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_ABJUANBIAOJI &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_XUANZUOTI &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_PAGE &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA_QUESTION &schema_element); static bool deserialize(const rapidjson::Value &json, SCHEMA &_schema); static bool deserialize(const rapidjson::Value &json, SCHEMA_VERSION &version); /*************************************/ template static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const char v[]){ json.AddMember(rapidjson::Value::StringRefType(name), rapidjson::Value::StringRefType(static_cast(v)), allocator); } template static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const std::string& v){ json.AddMember(rapidjson::Value::StringRefType(name), rapidjson::Value::StringRefType(v.c_str(), v.length()), allocator); } template static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const T& v){ json.AddMember(rapidjson::Value::StringRefType(name), v, allocator); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_QUESTION& schema_element){ serialize(json, allocator, "nID", schema_element.nID); serialize(json, allocator, "question_code", schema_element.question_code); serialize(json, allocator, "question_code_new", schema_element.question_code_new); serialize(json, allocator, "newqt", schema_element.newqt); serialize(json, allocator, "xiaowen", schema_element.xiaowen); serialize(json, allocator, "maxQuestionNO", schema_element.maxQuestionNO); serialize(json, allocator, "tigan", schema_element.tigan); serialize(json, allocator, "answers", schema_element.answers); serialize(json, allocator, "answerA", schema_element.answerA); serialize(json, allocator, "answerB", schema_element.answerB); serialize(json, allocator, "jiexi", schema_element.jiexi); serialize(json, allocator, "zhishidian", schema_element.zhishidian); serialize(json, allocator, "courseCode", schema_element.courseCode); serialize(json, allocator, "score", schema_element.score); serialize(json, allocator, "halfScore", schema_element.halfScore); serialize(json, allocator, "doubleEvl", schema_element.doubleEvl); serialize(json, allocator, "holdValue", schema_element.holdValue); serialize(json, allocator, "questionType", schema_element.questionType); serialize(json, allocator, "nMarkUnit", schema_element.nMarkUnit); serialize(json, allocator, "openOption", schema_element.openOption); serialize(json, allocator, "nLevelOne", schema_element.qtLevelOne); serialize(json, allocator, "nLevelTwo", schema_element.qtLevelTwo); serialize(json, allocator, "nPostLevelOne", schema_element.qtPostLevelOne); serialize(json, allocator, "nPostLevelTwo", schema_element.qtPostLevelTwo); serialize(json, allocator, "showMarkTypeIndex", schema_element.showMarkTypeIndex); serialize(json, allocator, "postMarkTypeID", schema_element.postMarkTypeID); serialize(json, allocator, "showSubjectTypeIndex", schema_element.showSubjectTypeIndex); serialize(json, allocator, "postSubjectTypeID", schema_element.postSubjectTypeID); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_RECT_FIELD& schema_element){ serialize(json, allocator, "centerx", schema_element.centerx); serialize(json, allocator, "centery", schema_element.centery); serialize(json, allocator, "height", schema_element.height); serialize(json, allocator, "width", schema_element.width); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_ELEMENT_FIELD& schema_element){ serialize(json, allocator, "nID", schema_element.nID); serialize(json, allocator, static_cast&>(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX& schema_element){ serialize(json, allocator, "nRows", schema_element.nRows); serialize(json, allocator, "nCols", schema_element.nCols); serialize(json, allocator, "optionWidth", schema_element.optionWidth); serialize(json, allocator, "optionHeight", schema_element.optionHeight); serialize(json, allocator, "direction", schema_element.direction); serialize(json, allocator, "outputchars", schema_element.outputchars); serialize(json, allocator, "outputcharsnew", schema_element.outputcharsnew); serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_KEGUANTI& schema_element){ rapidjson::Value question_groups(rapidjson::kArrayType); for (int idx_i = 0, idx_q = 0; idx_i < schema_element.group_count; idx_i++) { rapidjson::Value question_ids(rapidjson::kArrayType); for (int idx_j = 0; idx_j < schema_element.group_size[idx_i]; idx_j++, idx_q++){ question_ids.PushBack(schema_element.question_ids[idx_q], allocator); } question_groups.PushBack(question_ids, allocator); } json.AddMember("question_ids", question_groups, allocator); serialize(json, allocator, "question_type", schema_element.question_type); serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOCATE_POINT& schema_element){ serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOCATE_AREA& schema_element){ serialize(json, allocator, static_cast(schema_element)); } /*SCHEMA_LOACTE_CROSS*/ template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOACTE_CROSS& schema_element){ serialize(json, allocator, "sign", schema_element.sign); serialize(json, allocator, "angle", schema_element.angle); serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_TIANTUKAOHAO& schema_element){ serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_QUEKAOBIAOJI& schema_element){ serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_ABJUANBIAOJI& schema_element){ serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_XUANZUOTI& schema_element){ serialize(json, allocator, "xuantishu", schema_element.xuantishu); serialize(json, allocator, "err_handler_type", schema_element.err_handler_type); serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_CODE& schema_element){ serialize(json, allocator, "bDirection", schema_element.bDirection); serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_CLIP& schema_element){ rapidjson::Value question_ids(rapidjson::kArrayType); for (int idx_i = 0; idx_i < schema_element.question_count; idx_i++) { question_ids.PushBack(schema_element.question_ids[idx_i], allocator); } serialize(json, allocator, "area_name", schema_element.area_name); serialize(json, allocator, "markUnit", schema_element.markUnit); serialize(json, allocator, "issplit", schema_element.issplit); serialize(json, allocator, "markUnitPart", schema_element.markUnitPart); serialize(json, allocator, "question_type", schema_element.question_type); serialize(json, allocator, "area_name_by_questionNo", schema_element.area_name_by_questionNo); serialize(json, allocator, "area_name_by_questionNoNew", schema_element.area_name_by_questionNoNew); serialize(json, allocator, "xuanzutiArea", schema_element.xuanzutiArea); json.AddMember("question_ids", question_ids, allocator); serialize(json, allocator, static_cast(schema_element)); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_PAGE& schema_element){ serialize(json, allocator, "abjuanbjiaoji", schema_element.abjuanbjiaoji); serialize(json, allocator, "clips", schema_element.clips); serialize(json, allocator, "clips2", schema_element.clips2); serialize(json, allocator, "codes", schema_element.codes); serialize(json, allocator, "keguantiMatrix", schema_element.keguantiMatrix); serialize(json, allocator, "locateAreas", schema_element.locateAreas); serialize(json, allocator, "locateCrosses", schema_element.locateCrosses); serialize(json, allocator, "locatePoints", schema_element.locatePoints); serialize(json, allocator, "matrixs", schema_element.matrixs); serialize(json, allocator, "quekaobiaoji", schema_element.quekaobiaoji); serialize(json, allocator, "tiantukaohao", schema_element.tiantukaohao); serialize(json, allocator, "xuanzuoti", schema_element.xuanzuoti); serialize(json, allocator, "angle", schema_element.angle); serialize(json, allocator, "height", schema_element.height); serialize(json, allocator, "index", schema_element.index); serialize(json, allocator, "nID", schema_element.nID); serialize(json, allocator, "width", schema_element.width); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const std::vector& schema_elements){ rapidjson::Value array_(rapidjson::kArrayType); for (int idx_i = 0; idx_i < schema_elements.size(); idx_i++) { rapidjson::Value elment(rapidjson::kObjectType); const T & element_ = schema_elements[idx_i]; serialize(elment, allocator, element_); array_.PushBack(elment, allocator); } json.AddMember(rapidjson::Value::StringRefType(name), array_, allocator); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const SCHEMA_VERSION& version){ rapidjson::Value object_(rapidjson::kObjectType); serialize(object_, allocator, "majorNum", version.majorNum); serialize(object_, allocator, "minorNum", version.minorNum); serialize(object_, allocator, "company", version.company); json.AddMember(rapidjson::Value::StringRefType(name), object_, allocator); } template static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const SCHEMA& schema_element){ rapidjson::Value object_(rapidjson::kObjectType); serialize(object_, allocator, "course_code", schema_element.course_code); // serialize(object_, allocator, "strTimu", schema_element.strTiMuTotal); serialize(object_, allocator, "lastKeGuanTiDirection", schema_element.lastKeGuanTiDirection); serialize(object_, allocator, "nNextObjID", schema_element.nNextObjID); serialize(object_, allocator, "state", schema_element.state); serialize(object_, allocator, "totalScore", schema_element.totalScore); serialize(object_, allocator, "pages", schema_element.pages); serialize(object_, allocator, "questions", schema_element.questions); json.AddMember(rapidjson::Value::StringRefType(name), object_, allocator); } templatestatic inline void deserialize(T&dst, const rapidjson::Value &json){ dst = (T)json.GetInt(); } static inline void deserialize(float&dst, const rapidjson::Value &json){ dst = json.GetDouble(); } static inline void deserialize(double&dst, const rapidjson::Value &json){ dst = json.GetDouble(); } static inline void deserialize(bool&dst, const rapidjson::Value &json){ dst = json.GetBool(); } static inline void deserialize(int&dst, const rapidjson::Value &json){ dst = json.GetInt(); } static inline void deserialize(char dst[], const rapidjson::Value &json){ strcpy(dst, json.GetString()); } templatestatic inline void deserialize(T dst[], int& count, int group_size[], int& group_count, const rapidjson::Value &json){ group_count = json.Size(); count = 0; for (int idx_i = 0, idx_x = 0; idx_i < json.Size(); idx_i++) { const rapidjson::Value &json2 = json[idx_i]; group_size[idx_i] = json2.Size(); for (int idx_j = 0; idx_j < group_size[idx_i]; idx_j++, idx_x++) { deserialize(dst[idx_x], json2[idx_j]); count++; } } } templatestatic inline void deserialize(T dst[], int& count, const rapidjson::Value &json){ count = json.Size(); for (int idx_i = 0; idx_i < count; idx_i++) { deserialize(dst[idx_i], json[idx_i]); } } static inline void deserialize(std::string & dst, const rapidjson::Value &json){ dst = json.GetString(); } templatestatic bool deserialize(const rapidjson::Value &json, SCHEMA_RECT_FIELD &schema_element){ deserialize(schema_element.centerx, json["centerx"]); deserialize(schema_element.centery, json["centery"]); deserialize(schema_element.width, json["width"]); deserialize(schema_element.height, json["height"]); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_ELEMENT_FIELD &schema_element){ deserialize(schema_element.nID, json["nID"]); deserialize(json, static_cast&>(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX &schema_element){ deserialize(schema_element.nRows, json["nRows"]); deserialize(schema_element.nCols, json["nCols"]); deserialize(schema_element.optionWidth, json["optionWidth"]); deserialize(schema_element.optionHeight, json["optionHeight"]); deserialize(schema_element.direction, json["direction"]); deserialize(schema_element.outputchars, json["outputchars"]); deserialize(schema_element.outputcharsnew, json["outputcharsnew"]); deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_CLIP &schema_element){ deserialize(schema_element.area_name, json["area_name"]); deserialize(schema_element.markUnit, json["markUnit"]); deserialize(schema_element.issplit, json["issplit"]); deserialize(schema_element.markUnitPart, json["markUnitPart"]); deserialize(schema_element.question_type, json["question_type"]); deserialize(schema_element.area_name_by_questionNo, json["area_name_by_questionNo"]); deserialize(schema_element.area_name_by_questionNoNew, json["area_name_by_questionNoNew"]); deserialize(schema_element.question_ids, schema_element.question_count, json["question_ids"]); if (json.HasMember("xuanzutiArea")) deserialize(schema_element.xuanzutiArea, json["xuanzutiArea"]); deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_CODE &schema_element){ deserialize(schema_element.bDirection, json["bDirection"]); deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_LOCATE_AREA &schema_element){ deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_LOACTE_CROSS &schema_element){ if (json.FindMember("sign") != json.MemberEnd())deserialize(schema_element.sign, json["sign"]); if (json.FindMember("angle") != json.MemberEnd())deserialize(schema_element.angle, json["angle"]); deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_LOCATE_POINT &schema_element){ deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_QUEKAOBIAOJI &schema_element){ deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_TIANTUKAOHAO &schema_element){ deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_ABJUANBIAOJI &schema_element){ deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_KEGUANTI &schema_element){ deserialize(schema_element.question_type, json["question_type"]); deserialize(schema_element.question_ids, schema_element.question_count, schema_element.group_size, schema_element.group_count, json["question_ids"]); deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_XUANZUOTI &schema_element){ deserialize(schema_element.xuantishu, json["xuantishu"]); deserialize(schema_element.err_handler_type, json["err_handler_type"]); deserialize(json, static_cast(schema_element)); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_PAGE &schema_element){ deserialize(schema_element.abjuanbjiaoji, json["abjuanbjiaoji"]); deserialize(schema_element.angle, json["angle"]); deserialize(schema_element.clips, json["clips"]); deserialize(schema_element.clips2, json["clips2"]); deserialize(schema_element.codes, json["codes"]); deserialize(schema_element.height, json["height"]); deserialize(schema_element.index, json["index"]); deserialize(schema_element.keguantiMatrix, json["keguantiMatrix"]); deserialize(schema_element.locateAreas, json["locateAreas"]); deserialize(schema_element.locateCrosses, json["locateCrosses"]); deserialize(schema_element.locatePoints, json["locatePoints"]); deserialize(schema_element.matrixs, json["matrixs"]); deserialize(schema_element.nID, json["nID"]); deserialize(schema_element.quekaobiaoji, json["quekaobiaoji"]); deserialize(schema_element.tiantukaohao, json["tiantukaohao"]); deserialize(schema_element.width, json["width"]); deserialize(schema_element.xuanzuoti, json["xuanzuoti"]); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_QUESTION &schema_element){ deserialize(schema_element.answerA, json["answerA"]); deserialize(schema_element.answerB, json["answerB"]); deserialize(schema_element.answers, json["answers"]); deserialize(schema_element.courseCode, json["courseCode"]); deserialize(schema_element.doubleEvl, json["doubleEvl"]); deserialize(schema_element.halfScore, json["halfScore"]); deserialize(schema_element.holdValue, json["holdValue"]); deserialize(schema_element.jiexi, json["jiexi"]); deserialize(schema_element.nID, json["nID"]); deserialize(schema_element.nMarkUnit, json["nMarkUnit"]); deserialize(schema_element.openOption, json["openOption"]); deserialize(schema_element.questionType, json["questionType"]); deserialize(schema_element.question_code, json["question_code"]); deserialize(schema_element.question_code_new, json["question_code_new"]); deserialize(schema_element.newqt, json["newqt"]); deserialize(schema_element.xiaowen, json["xiaowen"]); if (json.HasMember("maxQuestionNO")) deserialize(schema_element.maxQuestionNO, json["maxQuestionNO"]); deserialize(schema_element.score, json["score"]); deserialize(schema_element.tigan, json["tigan"]); deserialize(schema_element.zhishidian, json["zhishidian"]); deserialize(schema_element.qtLevelOne, json["nLevelOne"]); deserialize(schema_element.qtLevelTwo, json["nLevelTwo"]); deserialize(schema_element.qtPostLevelOne, json["nPostLevelOne"]); deserialize(schema_element.qtPostLevelTwo, json["nPostLevelTwo"]); deserialize(schema_element.showMarkTypeIndex, json["showMarkTypeIndex"]); deserialize(schema_element.postMarkTypeID, json["postMarkTypeID"]); deserialize(schema_element.showSubjectTypeIndex, json["showSubjectTypeIndex"]); deserialize(schema_element.postSubjectTypeID, json["postSubjectTypeID"]); return true; } templatestatic bool deserialize(std::vector &schema_elements, const rapidjson::Value &json){ schema_elements.resize(json.Size()); for (int idx_i = 0; idx_i < json.Size(); idx_i++) { deserialize(json[idx_i], schema_elements[idx_i]); } return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA &_schema){ deserialize(_schema.course_code, json["course_code"]); //deserialize(_schema.strTiMuTotal, json["strTimu"]); deserialize(_schema.nNextObjID, json["nNextObjID"]); deserialize(_schema.state, json["state"]); deserialize(_schema.totalScore, json["totalScore"]); deserialize(_schema.questions, json["questions"]); deserialize(_schema.pages, json["pages"]); return true; } static bool deserialize(const rapidjson::Value &json, SCHEMA_VERSION &version){ deserialize(version.majorNum, json["majorNum"]); deserialize(version.minorNum, json["minorNum"]); deserialize(version.company, json["company"]); return true; } } void SchemJsonSerializor::serialize(std::string &json, const schema::SCHEMA & _schema, const SCHEMA_VERSION &version /*= CURRENT_SCHEMA_VERSTION*/) { rapidjson::Document document; rapidjson::Document::AllocatorType & allocator = document.GetAllocator(); rapidjson::Value root(rapidjson::kObjectType); ::schema::serializor::serialize(root, allocator,"schemaVersion", version); ::schema::serializor::serialize(root, allocator, "schema", _schema); rapidjson::StringBuffer buffer; rapidjson::Writer writer(buffer); root.Accept(writer); json = buffer.GetString(); } bool SchemJsonSerializor::deserialize(const std::string &json, schema::SCHEMA & _schema, SCHEMA_VERSION &version) { rapidjson::Document document; document.Parse(json.c_str()); if (document.IsObject()){ bool success = ::schema::serializor::deserialize(document["schemaVersion"], version); if (!success) return false; success = ::schema::serializor::deserialize(document["schema"], _schema); if (!success) return false; return true; } return false; } } }