test_sample_json_converter.h.golden 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // GENERATED FILE
  2. // This file generated by DomDistillerJs protoc plugin.
  3. #include "test_sample.pb.h"
  4. // base dependencies
  5. #include "base/values.h"
  6. #include <memory>
  7. #include <string>
  8. #include <utility>
  9. namespace dom_distiller {
  10. namespace test_sample {
  11. namespace proto {
  12. namespace json {
  13. class TypeTest {
  14. public:
  15. class Message {
  16. public:
  17. static bool ReadFromValue(const base::Value& dict, dom_distiller::test_sample::proto::TypeTest::Message* message) {
  18. if (!dict.is_dict()) goto error;
  19. if (const auto* value = dict.FindKey("1")) {
  20. if (!(*value).is_bool()) {
  21. goto error;
  22. }
  23. message->set_dummy(value->GetBool());
  24. }
  25. return true;
  26. error:
  27. return false;
  28. }
  29. static base::Value WriteToValue(const dom_distiller::test_sample::proto::TypeTest::Message& message) {
  30. base::Value dict(base::Value::Type::DICTIONARY);
  31. if (message.has_dummy()) {
  32. dict.SetBoolKey("1", message.dummy());
  33. }
  34. return dict;
  35. }
  36. };
  37. static bool ReadFromValue(const base::Value& dict, dom_distiller::test_sample::proto::TypeTest* message) {
  38. if (!dict.is_dict()) goto error;
  39. if (const auto* value = dict.FindKey("1")) {
  40. if (!((*value).is_int() || (*value).is_double())) {
  41. goto error;
  42. }
  43. message->set_float_value(value->GetDouble());
  44. }
  45. if (const auto* value = dict.FindKey("2")) {
  46. if (!((*value).is_int() || (*value).is_double())) {
  47. goto error;
  48. }
  49. message->set_double_value(value->GetDouble());
  50. }
  51. if (const auto* value = dict.FindKey("3")) {
  52. if (!(*value).is_int()) {
  53. goto error;
  54. }
  55. message->set_int32_value(value->GetInt());
  56. }
  57. if (const auto* value = dict.FindKey("4")) {
  58. if (!(*value).is_bool()) {
  59. goto error;
  60. }
  61. message->set_bool_value(value->GetBool());
  62. }
  63. if (const auto* value = dict.FindKey("5")) {
  64. if (!(*value).is_string()) {
  65. goto error;
  66. }
  67. message->set_string_value(value->GetString());
  68. }
  69. if (const auto* value = dict.FindKey("6")) {
  70. if (!dom_distiller::test_sample::proto::json::TypeTest::Message::ReadFromValue(*value, message->mutable_message_value())) {
  71. goto error;
  72. }
  73. }
  74. return true;
  75. error:
  76. return false;
  77. }
  78. static base::Value WriteToValue(const dom_distiller::test_sample::proto::TypeTest& message) {
  79. base::Value dict(base::Value::Type::DICTIONARY);
  80. if (message.has_float_value()) {
  81. dict.SetDoubleKey("1", message.float_value());
  82. }
  83. if (message.has_double_value()) {
  84. dict.SetDoubleKey("2", message.double_value());
  85. }
  86. if (message.has_int32_value()) {
  87. dict.SetIntKey("3", message.int32_value());
  88. }
  89. if (message.has_bool_value()) {
  90. dict.SetBoolKey("4", message.bool_value());
  91. }
  92. if (message.has_string_value()) {
  93. dict.SetStringKey("5", message.string_value());
  94. }
  95. if (message.has_message_value()) {
  96. dict.SetKey("6",
  97. dom_distiller::test_sample::proto::json::TypeTest::Message::WriteToValue(
  98. message.message_value()));
  99. }
  100. return dict;
  101. }
  102. };
  103. class Repeated {
  104. public:
  105. class Message {
  106. public:
  107. static bool ReadFromValue(const base::Value& dict, dom_distiller::test_sample::proto::Repeated::Message* message) {
  108. if (!dict.is_dict()) goto error;
  109. if (const auto* value = dict.FindKey("1")) {
  110. if (!value->is_list()) {
  111. goto error;
  112. }
  113. for (const auto& element : value->GetListDeprecated()) {
  114. if (!element.is_bool()) {
  115. goto error;
  116. }
  117. message->add_dummy(element.GetBool());
  118. }
  119. }
  120. return true;
  121. error:
  122. return false;
  123. }
  124. static base::Value WriteToValue(const dom_distiller::test_sample::proto::Repeated::Message& message) {
  125. base::Value dict(base::Value::Type::DICTIONARY);
  126. {
  127. const auto& repeated_field = message.dummy();
  128. base::Value::List field_list;
  129. field_list.reserve(repeated_field.size());
  130. for (const auto& element : repeated_field) {
  131. field_list.Append(element);
  132. }
  133. dict.SetKey("1",
  134. base::Value(std::move(field_list)));
  135. }
  136. return dict;
  137. }
  138. };
  139. static bool ReadFromValue(const base::Value& dict, dom_distiller::test_sample::proto::Repeated* message) {
  140. if (!dict.is_dict()) goto error;
  141. if (const auto* value = dict.FindKey("1")) {
  142. if (!value->is_list()) {
  143. goto error;
  144. }
  145. for (const auto& element : value->GetListDeprecated()) {
  146. if (!(element.is_int() || element.is_double())) {
  147. goto error;
  148. }
  149. message->add_float_value(element.GetDouble());
  150. }
  151. }
  152. if (const auto* value = dict.FindKey("2")) {
  153. if (!value->is_list()) {
  154. goto error;
  155. }
  156. for (const auto& element : value->GetListDeprecated()) {
  157. if (!(element.is_int() || element.is_double())) {
  158. goto error;
  159. }
  160. message->add_double_value(element.GetDouble());
  161. }
  162. }
  163. if (const auto* value = dict.FindKey("3")) {
  164. if (!value->is_list()) {
  165. goto error;
  166. }
  167. for (const auto& element : value->GetListDeprecated()) {
  168. if (!element.is_int()) {
  169. goto error;
  170. }
  171. message->add_int32_value(element.GetInt());
  172. }
  173. }
  174. if (const auto* value = dict.FindKey("4")) {
  175. if (!value->is_list()) {
  176. goto error;
  177. }
  178. for (const auto& element : value->GetListDeprecated()) {
  179. if (!element.is_bool()) {
  180. goto error;
  181. }
  182. message->add_bool_value(element.GetBool());
  183. }
  184. }
  185. if (const auto* value = dict.FindKey("5")) {
  186. if (!value->is_list()) {
  187. goto error;
  188. }
  189. for (const auto& element : value->GetListDeprecated()) {
  190. if (!element.is_string()) {
  191. goto error;
  192. }
  193. message->add_string_value(element.GetString());
  194. }
  195. }
  196. if (const auto* value = dict.FindKey("6")) {
  197. if (!value->is_list()) {
  198. goto error;
  199. }
  200. for (const auto& element : value->GetListDeprecated()) {
  201. if (!dom_distiller::test_sample::proto::json::Repeated::Message::ReadFromValue(element, message->add_message_value())) {
  202. goto error;
  203. }
  204. }
  205. }
  206. return true;
  207. error:
  208. return false;
  209. }
  210. static base::Value WriteToValue(const dom_distiller::test_sample::proto::Repeated& message) {
  211. base::Value dict(base::Value::Type::DICTIONARY);
  212. {
  213. const auto& repeated_field = message.float_value();
  214. base::Value::List field_list;
  215. field_list.reserve(repeated_field.size());
  216. for (const auto& element : repeated_field) {
  217. field_list.Append(element);
  218. }
  219. dict.SetKey("1",
  220. base::Value(std::move(field_list)));
  221. }
  222. {
  223. const auto& repeated_field = message.double_value();
  224. base::Value::List field_list;
  225. field_list.reserve(repeated_field.size());
  226. for (const auto& element : repeated_field) {
  227. field_list.Append(element);
  228. }
  229. dict.SetKey("2",
  230. base::Value(std::move(field_list)));
  231. }
  232. {
  233. const auto& repeated_field = message.int32_value();
  234. base::Value::List field_list;
  235. field_list.reserve(repeated_field.size());
  236. for (const auto& element : repeated_field) {
  237. field_list.Append(element);
  238. }
  239. dict.SetKey("3",
  240. base::Value(std::move(field_list)));
  241. }
  242. {
  243. const auto& repeated_field = message.bool_value();
  244. base::Value::List field_list;
  245. field_list.reserve(repeated_field.size());
  246. for (const auto& element : repeated_field) {
  247. field_list.Append(element);
  248. }
  249. dict.SetKey("4",
  250. base::Value(std::move(field_list)));
  251. }
  252. {
  253. const auto& repeated_field = message.string_value();
  254. base::Value::List field_list;
  255. field_list.reserve(repeated_field.size());
  256. for (const auto& element : repeated_field) {
  257. field_list.Append(element);
  258. }
  259. dict.SetKey("5",
  260. base::Value(std::move(field_list)));
  261. }
  262. {
  263. const auto& repeated_field = message.message_value();
  264. base::Value::List field_list;
  265. field_list.reserve(repeated_field.size());
  266. for (const auto& element : repeated_field) {
  267. field_list.Append(
  268. dom_distiller::test_sample::proto::json::Repeated::Message::WriteToValue(element));
  269. }
  270. dict.SetKey("6",
  271. base::Value(std::move(field_list)));
  272. }
  273. return dict;
  274. }
  275. };
  276. }
  277. }
  278. }
  279. }