// GENERATED FILE
// This file generated by DomDistillerJs protoc plugin.
#include "test_sample.pb.h"
// base dependencies
#include "base/values.h"
#include <memory>
#include <string>
#include <utility>
namespace dom_distiller {
namespace test_sample {
namespace proto {
namespace json {
class TypeTest {
public:
class Message {
public:
static bool ReadFromValue(const base::Value& dict_value, dom_distiller::test_sample::proto::TypeTest::Message* message) {
const base::Value::Dict* dict = dict_value.GetIfDict();
if (!dict) goto error;
if (const auto* value = dict->Find("1")) {
if (!(*value).is_bool()) {
goto error;
}
message->set_dummy(value->GetBool());
}
return true;
error:
return false;
}
static base::Value WriteToValue(const dom_distiller::test_sample::proto::TypeTest::Message& message) {
base::Value::Dict dict;
if (message.has_dummy()) {
dict.Set("1", message.dummy());
}
return base::Value(std::move(dict));
}
};
static bool ReadFromValue(const base::Value& dict_value, dom_distiller::test_sample::proto::TypeTest* message) {
const base::Value::Dict* dict = dict_value.GetIfDict();
if (!dict) goto error;
if (const auto* value = dict->Find("1")) {
if (!((*value).is_int() || (*value).is_double())) {
goto error;
}
message->set_float_value(value->GetDouble());
}
if (const auto* value = dict->Find("2")) {
if (!((*value).is_int() || (*value).is_double())) {
goto error;
}
message->set_double_value(value->GetDouble());
}
if (const auto* value = dict->Find("3")) {
if (!(*value).is_int()) {
goto error;
}
message->set_int32_value(value->GetInt());
}
if (const auto* value = dict->Find("4")) {
if (!(*value).is_bool()) {
goto error;
}
message->set_bool_value(value->GetBool());
}
if (const auto* value = dict->Find("5")) {
if (!(*value).is_string()) {
goto error;
}
message->set_string_value(value->GetString());
}
if (const auto* value = dict->Find("6")) {
if (!dom_distiller::test_sample::proto::json::TypeTest::Message::ReadFromValue(*value, message->mutable_message_value())) {
goto error;
}
}
return true;
error:
return false;
}
static base::Value WriteToValue(const dom_distiller::test_sample::proto::TypeTest& message) {
base::Value::Dict dict;
if (message.has_float_value()) {
dict.Set("1", message.float_value());
}
if (message.has_double_value()) {
dict.Set("2", message.double_value());
}
if (message.has_int32_value()) {
dict.Set("3", message.int32_value());
}
if (message.has_bool_value()) {
dict.Set("4", message.bool_value());
}
if (message.has_string_value()) {
dict.Set("5", message.string_value());
}
if (message.has_message_value()) {
dict.Set("6",
dom_distiller::test_sample::proto::json::TypeTest::Message::WriteToValue(
message.message_value()));
}
return base::Value(std::move(dict));
}
};
class Repeated {
public:
class Message {
public:
static bool ReadFromValue(const base::Value& dict_value, dom_distiller::test_sample::proto::Repeated::Message* message) {
const base::Value::Dict* dict = dict_value.GetIfDict();
if (!dict) goto error;
if (const auto* value = dict->Find("1")) {
if (!value->is_list()) {
goto error;
}
for (const auto& element : value->GetList()) {
if (!element.is_bool()) {
goto error;
}
message->add_dummy(element.GetBool());
}
}
return true;
error:
return false;
}
static base::Value WriteToValue(const dom_distiller::test_sample::proto::Repeated::Message& message) {
base::Value::Dict dict;
{
const auto& repeated_field = message.dummy();
base::Value::List field_list;
field_list.reserve(repeated_field.size());
for (const auto& element : repeated_field) {
field_list.Append(element);
}
dict.Set("1", std::move(field_list));
}
return base::Value(std::move(dict));
}
};
static bool ReadFromValue(const base::Value& dict_value, dom_distiller::test_sample::proto::Repeated* message) {
const base::Value::Dict* dict = dict_value.GetIfDict();
if (!dict) goto error;
if (const auto* value = dict->Find("1")) {
if (!value->is_list()) {
goto error;
}
for (const auto& element : value->GetList()) {
if (!(element.is_int() || element.is_double())) {
goto error;
}
message->add_float_value(element.GetDouble());
}
}
if (const auto* value = dict->Find("2")) {
if (!value->is_list()) {
goto error;
}
for (const auto& element : value->GetList()) {
if (!(element.is_int() || element.is_double())) {
goto error;
}
message->add_double_value(element.GetDouble());
}
}
if (const auto* value = dict->Find("3")) {
if (!value->is_list()) {
goto error;
}
for (const auto& element : value->GetList()) {
if (!element.is_int()) {
goto error;
}
message->add_int32_value(element.GetInt());
}
}
if (const auto* value = dict->Find("4")) {
if (!value->is_list()) {
goto error;
}
for (const auto& element : value->GetList()) {
if (!element.is_bool()) {
goto error;
}
message->add_bool_value(element.GetBool());
}
}
if (const auto* value = dict->Find("5")) {
if (!value->is_list()) {
goto error;
}
for (const auto& element : value->GetList()) {
if (!element.is_string()) {
goto error;
}
message->add_string_value(element.GetString());
}
}
if (const auto* value = dict->Find("6")) {
if (!value->is_list()) {
goto error;
}
for (const auto& element : value->GetList()) {
if (!dom_distiller::test_sample::proto::json::Repeated::Message::ReadFromValue(element, message->add_message_value())) {
goto error;
}
}
}
return true;
error:
return false;
}
static base::Value WriteToValue(const dom_distiller::test_sample::proto::Repeated& message) {
base::Value::Dict dict;
{
const auto& repeated_field = message.float_value();
base::Value::List field_list;
field_list.reserve(repeated_field.size());
for (const auto& element : repeated_field) {
field_list.Append(element);
}
dict.Set("1", std::move(field_list));
}
{
const auto& repeated_field = message.double_value();
base::Value::List field_list;
field_list.reserve(repeated_field.size());
for (const auto& element : repeated_field) {
field_list.Append(element);
}
dict.Set("2", std::move(field_list));
}
{
const auto& repeated_field = message.int32_value();
base::Value::List field_list;
field_list.reserve(repeated_field.size());
for (const auto& element : repeated_field) {
field_list.Append(element);
}
dict.Set("3", std::move(field_list));
}
{
const auto& repeated_field = message.bool_value();
base::Value::List field_list;
field_list.reserve(repeated_field.size());
for (const auto& element : repeated_field) {
field_list.Append(element);
}
dict.Set("4", std::move(field_list));
}
{
const auto& repeated_field = message.string_value();
base::Value::List field_list;
field_list.reserve(repeated_field.size());
for (const auto& element : repeated_field) {
field_list.Append(element);
}
dict.Set("5", std::move(field_list));
}
{
const auto& repeated_field = message.message_value();
base::Value::List field_list;
field_list.reserve(repeated_field.size());
for (const auto& element : repeated_field) {
field_list.Append(
dom_distiller::test_sample::proto::json::Repeated::Message::WriteToValue(element));
}
dict.Set("6", std::move(field_list));
}
return base::Value(std::move(dict));
}
};
}
}
}
}