From da5249bf529d2d5e0f89aed5775b76a56d50dd8c Mon Sep 17 00:00:00 2001 From: wpz <1249632539@qq.com> Date: 星期三, 02 七月 2025 15:30:59 +0800 Subject: [PATCH] Merge branch 'master' of ssh://115.28.86.8:29418/~admin/智能网联_25-0305_617_v1 --- Server/common_type.h | 104 ++++++++++++++++++++++++++++++++++----------------- 1 files changed, 69 insertions(+), 35 deletions(-) diff --git a/Server/common_type.h b/Server/common_type.h index f9524ae..22b8098 100644 --- a/Server/common_type.h +++ b/Server/common_type.h @@ -1,31 +1,44 @@ #ifndef TCPDATATYPE_H #define TCPDATATYPE_H -/* */ + +/* + * 瀹㈡埛绔笌鏈嶅姟鍣ㄤ氦浜掔殑鍔ㄤ綔绫诲瀷鏋氫妇 + * 娉ㄦ剰锛氫娇鐢� enum class 閬垮厤鍛藉悕鍐茬獊锛圕++11鐗规�э級 + */ enum class ActionType { - HeartCheck = 100, - Login = 110, - Register = 120, - Msg = 200, - Download = 300 + HeartCheck = 100, // 蹇冭烦妫�娴嬶紙淇濇寔杩炴帴娲绘�э級 + Login = 110, // 鐧诲綍璇锋眰 + Register = 120, // 娉ㄥ唽璇锋眰 + Msg = 200, // 鏅�氭秷鎭紶杈� + Download = 300 // 鏂囦欢涓嬭浇璇锋眰 }; -/* 慰 HTTP 应 */ + +/* + * HTTP椋庢牸鍝嶅簲鐘舵�佺爜锛堢畝鍖栫増锛� + * 鐢ㄤ簬鏈嶅姟鍣ㄥ悜瀹㈡埛绔繑鍥炴搷浣滅粨鏋滅姸鎬� + */ enum class ResponseCode { - ResponseOK = 200, // 晒 - BadRequest = 400, // 突 螅 薹 - Unauthorized = 401, // 要 没 证 - Forbidden = 403, // 突 说 螅 蔷芫 执 写 - NotFound = 404, // 薹 业 源 - MethodNotAllowed = 405 // 突 械姆 止 - + ResponseOK = 200, // 鎴愬姛锛圤K锛� + BadRequest = 400, // 閿欒璇锋眰锛堝鎴风璇锋眰璇硶閿欒锛� + Unauthorized = 401, // 鏈巿鏉冿紙闇�瑕佽韩浠介獙璇侊級 + Forbidden = 403, // 绂佹璁块棶锛堟潈闄愪笉瓒筹級 + NotFound = 404, // 鏈壘鍒帮紙璇锋眰璧勬簮涓嶅瓨鍦級 + MethodNotAllowed = 405 // 鏂规硶涓嶅厑璁革紙濡傜敤GET璇锋眰POST鎺ュ彛锛� }; -/* 息 */ + +/* + * 閫氱敤娑堟伅澶寸粨鏋勶紙鎵�鏈夋暟鎹寘蹇呴』鍖呭惈锛� + * 浣滅敤锛氭爣璇嗘秷鎭被鍨嬪拰鍩烘湰淇℃伅 + */ struct Head { - ActionType type; - int len; - int version; + ActionType type; // 娑堟伅绫诲瀷锛堝搴擜ctionType鏋氫妇锛� + int len; // 鏁翠釜鏁版嵁鍖呯殑闀垮害锛堝瓧鑺傛暟锛� + int version; // 鍗忚鐗堟湰鍙凤紙鐢ㄤ簬鍏煎鎬ф帶鍒讹級 + + // 鏋勯�犲嚱鏁帮紙鍒濆鍖栨椂蹇呴』鎻愪緵涓変釜鍙傛暟锛� Head(ActionType ptype, int plen, int pversion) { len = plen; @@ -33,40 +46,61 @@ version = pversion; } }; -struct HeartCheckReq // + +/* + * 蹇冭烦妫�娴嬭姹傜粨鏋� + * 鐗圭偣锛氬浐瀹氱被鍨嬪拰闀垮害锛堜笉闇�瑕侀澶栨暟鎹級 + */ +struct HeartCheckReq { - ActionType type; - int len; + ActionType type; // 鍥哄畾涓篈ctionType::HeartCheck + int len; // 缁撴瀯浣撹嚜韬ぇ灏� + HeartCheckReq() { type = ActionType::HeartCheck; - len = sizeof(HeartCheckReq); + len = sizeof(HeartCheckReq); // 鑷姩璁$畻缁撴瀯浣撳ぇ灏� } }; -struct HeartCheckRes // 应 +/* + * 蹇冭烦妫�娴嬪搷搴旂粨鏋� + * 娉ㄦ剰锛氫笌璇锋眰缁撴瀯鐩稿悓锛堝疄闄呭彲鑳藉寘鍚湇鍔″櫒鐘舵�佷俊鎭級 + */ +struct HeartCheckRes { - ActionType type; - int len; + ActionType type; // 鍥哄畾涓篈ctionType::HeartCheck + int len; // 缁撴瀯浣撹嚜韬ぇ灏� + HeartCheckRes() { type = ActionType::HeartCheck; len = sizeof(HeartCheckRes); } }; + +/* + * 鐢ㄦ埛娉ㄥ唽璇锋眰缁撴瀯 + * 缁勬垚锛氭秷鎭ご + 鐢ㄦ埛淇℃伅瀛楁 + */ struct RegisterRequest { - Head head; - char name[64]; - char password[64]; - char email[32]; - char phone[32]; + Head head; // 蹇呴』鍖呭惈鐨勬秷鎭ご + char name[64]; // 鐢ㄦ埛鍚嶏紙鍥哄畾闀垮害64瀛楄妭锛� + char password[64];// 瀵嗙爜锛堝缓璁姞瀵嗗瓨鍌級 + char email[32]; // 閭锛堢敤浜庢壘鍥炲瘑鐮侊級 + char phone[32]; // 鎵嬫満鍙凤紙鍙�夐獙璇侊級 }; + +/* + * 鐢ㄦ埛鐧诲綍璇锋眰缁撴瀯 + * 娉ㄦ剰锛氭瘮娉ㄥ唽璇锋眰灏戦偖绠卞拰鎵嬫満瀛楁 + */ struct LoginRequest { - - Head head; - char name[64]; - char password[64]; + Head head; // 娑堟伅澶达紙type搴斾负ActionType::Login锛� + char name[64]; // 鐢ㄦ埛鍚� + char password[64];// 瀵嗙爜锛堝缓璁姞瀵嗕紶杈擄級 }; -#endif + +#endif // TCPDATATYPE_H \ No newline at end of file -- Gitblit v1.8.0