PlayerDeviceList.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-02-15 15:48:43
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-02-16 09:24:27
  8. */
  9. #ifndef __PALYERDEVCELIST_H_
  10. #define __PALYERDEVCELIST_H_
  11. #include <iostream>
  12. #include <rapidjson/document.h>
  13. #include <rapidjson/rapidjson.h>
  14. #include <rapidjson/stringbuffer.h>
  15. #include <rapidjson/writer.h>
  16. using namespace std;
  17. class dSocket
  18. {
  19. public:
  20. bool removed;
  21. public:
  22. dSocket() {}
  23. ~dSocket() {}
  24. bool jsonToObject(const rapidjson::Value& object){
  25. const auto end = object.MemberEnd();
  26. if(end == object.FindMember("removed") || !object["removed"].IsBool()){
  27. return false;
  28. }else{
  29. removed = object["removed"].GetBool();
  30. }
  31. return true;
  32. }
  33. };
  34. class PlayerDeviceList
  35. {
  36. public:
  37. dSocket d_socket;
  38. std::string d_status;
  39. std::string did;
  40. std::string dname;
  41. std::string donline;
  42. std::string dtype;
  43. std::string ip_port;
  44. std::string loginDate;
  45. public:
  46. PlayerDeviceList(){}
  47. ~PlayerDeviceList(){}
  48. /**
  49. * @description: json转换为对象
  50. * @param {Value&} object
  51. * @return {*}
  52. */
  53. bool jsonToObject(const rapidjson::Value& object){
  54. const auto end = object.MemberEnd();
  55. if(end == object.FindMember("d_socket") || !object["d_socket"].IsObject()){
  56. return false;
  57. }
  58. else{
  59. const rapidjson::Value& obj = object["d_socket"];
  60. if(d_socket.jsonToObject(obj) == false) return false;
  61. }
  62. if(end == object.FindMember("d_status") || !object["d_status"].IsString()){
  63. return false;
  64. }
  65. else{
  66. d_status = object["d_status"].GetString();
  67. }
  68. if(end == object.FindMember("did") || !object["did"].IsString()){
  69. return false;
  70. }
  71. else{
  72. did = object["did"].GetString();
  73. }
  74. if(end == object.FindMember("dname") || !object["dname"].IsString()){
  75. return false;
  76. }
  77. else{
  78. dname = object["dname"].GetString();
  79. }
  80. if(end == object.FindMember("donline") || !object["donline"].IsString()){
  81. return false;
  82. }
  83. else{
  84. donline = object["donline"].GetString();
  85. }
  86. if(end == object.FindMember("dtype") || !object["dtype"].IsString()){
  87. return false;
  88. }
  89. else{
  90. dtype = object["dtype"].GetString();
  91. }
  92. if(end == object.FindMember("ip_port") || !object["ip_port"].IsString()){
  93. return false;
  94. }
  95. else{
  96. ip_port = object["ip_port"].GetString();
  97. }
  98. if(end == object.FindMember("loginDate") || !object["loginDate"].IsString()){
  99. return false;
  100. }
  101. else{
  102. loginDate = object["loginDate"].GetString();
  103. }
  104. return true;
  105. }
  106. };
  107. #endif