Google-ProtocolBuffers-Dynamic
view release on metacpan or search on metacpan
src/dynamic.cpp view on Meta::CPAN
if (options_ref == NULL || !SvOK(options_ref))
return;
if (!SvROK(options_ref) || SvTYPE(SvRV(options_ref)) != SVt_PVHV)
croak("options must be a hash reference");
HV *options = (HV *) SvRV(options_ref);
#define BOOLEAN_OPTION(field, name) { \
SV **value = hv_fetchs(options, #name, 0); \
if (value) \
field = SvTRUE(*value); \
}
BOOLEAN_OPTION(use_bigints, use_bigints);
BOOLEAN_OPTION(check_required_fields, check_required_fields);
BOOLEAN_OPTION(explicit_defaults, explicit_defaults);
BOOLEAN_OPTION(encode_defaults, encode_defaults);
BOOLEAN_OPTION(encode_defaults_proto3, encode_defaults_proto3);
BOOLEAN_OPTION(check_enum_values, check_enum_values);
BOOLEAN_OPTION(generic_extension_methods, generic_extension_methods);
BOOLEAN_OPTION(implicit_maps, implicit_maps);
BOOLEAN_OPTION(decode_blessed, decode_blessed);
BOOLEAN_OPTION(fail_ref_coercion, fail_ref_coercion);
BOOLEAN_OPTION(ignore_undef_fields, ignore_undef_fields);
#undef BOOLEAN_OPTION
#define START_STRING_VALUE(name) \
if (SV **value = hv_fetchs(options, #name, 0)) { \
const char *buf = SvPV_nolen(*value); \
\
if (0 == 1)
#define STRING_VALUE(field, string, value) \
else if (strEQ(buf, #string)) \
field = value
#define END_STRING_VALUE(name) \
else \
croak("Invalid value '%s' for '" #name "' option", buf); \
}
START_STRING_VALUE(default_decoder);
STRING_VALUE(default_decoder, upb, Upb);
STRING_VALUE(default_decoder, bbpb, Bbpb);
END_STRING_VALUE(default_decoder);
START_STRING_VALUE(accessor_style);
STRING_VALUE(accessor_style, get_and_set, GetAndSet);
STRING_VALUE(accessor_style, plain_and_set, PlainAndSet);
STRING_VALUE(accessor_style, single_accessor, SingleAccessor);
STRING_VALUE(accessor_style, plain, Plain);
END_STRING_VALUE(accessor_style);
START_STRING_VALUE(client_services);
STRING_VALUE(client_services, disable, Disable);
STRING_VALUE(client_services, noop, Noop);
STRING_VALUE(client_services, grpc_xs, GrpcXS);
END_STRING_VALUE(client_services);
START_STRING_VALUE(boolean_values);
STRING_VALUE(boolean_style, perl, Perl);
STRING_VALUE(boolean_style, numeric, Numeric);
STRING_VALUE(boolean_style, json, JSON);
END_STRING_VALUE(boolean_values);
#undef START_STRING_VALUE
#undef STRING_VALUE
#undef END_STRING_VALUE
}
Dynamic::Dynamic(const string &root_directory) :
descriptor_loader() {
if (!root_directory.empty())
descriptor_loader.map_disk_path("", root_directory);
}
Dynamic::~Dynamic() {
for (unordered_map<std::string, const Mapper *>::iterator it = descriptor_map.begin(), en = descriptor_map.end(); it != en; ++it)
it->second->unref();
}
void Dynamic::add_file_recursively(pTHX_ const FileDescriptor *file) {
files.insert(file);
for (int i = 0, max = file->dependency_count(); i < max; ++i)
add_file_recursively(aTHX_ file->dependency(i));
}
void Dynamic::load_file(pTHX_ const string &file) {
const FileDescriptor *loaded = descriptor_loader.load_proto(file);
if (loaded)
add_file_recursively(aTHX_ loaded);
descriptor_loader.maybe_croak();
}
void Dynamic::load_string(pTHX_ const string &file, SV *sv) {
STRLEN len;
const char *data = SvPV(sv, len);
string actual_file = file.empty() ? "<string>" : file;
descriptor_loader.add_memory_file(actual_file, data, len);
load_file(aTHX_ actual_file);
}
void Dynamic::load_serialized_string(pTHX_ SV *sv) {
STRLEN len;
const char *data = SvPV(sv, len);
const vector<const FileDescriptor *> loaded = descriptor_loader.load_serialized(data, len);
for (vector<const FileDescriptor *>::const_iterator it = loaded.begin(), en = loaded.end(); it != en; ++it)
add_file_recursively(aTHX_ *it);
descriptor_loader.maybe_croak();
}
void Dynamic::map_wkts(pTHX_ const MappingOptions &options) {
MappingOptions maybe_no_perl_names = options;
maybe_no_perl_names.no_redefine_perl_names = true;
map_package(aTHX_ "google.protobuf", "Google::ProtocolBuffers::Dynamic::WKT", maybe_no_perl_names);
}
namespace {
int free_refcounted(pTHX_ SV *sv, MAGIC *mg) {
Refcounted *refcounted = (Refcounted *) mg->mg_ptr;
( run in 1.041 second using v1.01-cache-2.11-cpan-39bf76dae61 )