Google-ProtocolBuffers-Dynamic
view release on metacpan or search on metacpan
0.41_09 2022-12-07 10:55:52 CET
- Fix per-mapping parameters in protoc plugin
0.41_08 2022-12-02 11:14:07 CET
- Support map_message/map_message_prefix options in protoc plugin
0.41_07 2022-11-25 10:54:01 CET
- Add missing 'boolean_values' option to protoc plugin
0.41_06 2022-11-11 19:40:44 CET
- Improve error message for duplicate package mapping
0.41_05 2022-11-02 12:23:49 CET
- Make sure decoded strings have a NUL after the last character
0.41_04 2022-11-01 14:08:23 CET
lib/Google/ProtocolBuffers/Dynamic.pm view on Meta::CPAN
made stricter in the future.
=head2 use_bigints
Enabled by default on Perls with 32-bit integers, disabled by default
on Perls with 64-bit integers.
When enabled, values that don't fit in a 32-bit integer are returned as
L<Math::BigInt> objects.
=head2 boolean_values
Defaults to C<perl>.
It controls how boolean values are mapped in Perl. Accepted values are:
=over 4
=item perl
Maps C<true> to C<1> and C<false> to C<"">.
lib/Google/ProtocolBuffers/Dynamic/MakeModule.pm view on Meta::CPAN
encode_defaults_proto3
check_enum_values
fail_ref_coercion
ignore_undef_fields
generic_extension_methods
);
my %string_options = map { $_ => 1 } qw(
accessor_style
client_services
boolean_values
);
sub _to_option {
my ($options, $key, $value) = @_;
if (exists $string_options{$key}) {
$options->{$key} = $value;
return 1;
}
return 0 unless my $boolean = $boolean_options{$key};
scripts/protoc-gen-perl-gpd view on Meta::CPAN
The following options map one to one to the C<options> key of
L<Google::ProtocolBuffers::Dynamic/map>. When specified before the
first mapping, they are applied to all mappings.
Boolean options: C<implicit_maps>, C<use_bigints>, C<check_required_fields>,
C<explicit_defaults>, C<encode_defaults>, C<encode_defaults_proto3>, C<check_enum_values>,
C<generic_extension_methods>. When specified they set the option value
to 1, when prefixed with C<no_> (e.g. C<no_use_bigints>) they set the
option value to 0.
String options: C<accessor_style>, C<client_services> and C<boolean_values>
set the corresponding option to the specified value
=head1 INSERTION POINTS
Generated code uses insertion points to enable customization via
C<protoc> plugins.
The
L<official documentation for insertion points|https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.compiler.plugin.pb>
offers more details on what insertion points are and how they can be
src/dynamic.cpp view on Meta::CPAN
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);
t/021_bool.t view on Meta::CPAN
use t::lib::Test;
my $encoded_true = "\x38\x01";
my $encoded_false = "\x38\x00";
my $encoded_default = "";
my $encoded_outer = "\x42\x02" . $encoded_true;
{
my $d = Google::ProtocolBuffers::Dynamic->new('t/proto');
$d->load_file("bool.proto");
$d->map_message("test.Bool", "PerlBool", { explicit_defaults => 1, boolean_values => 'perl', decode_blessed => 0 });
$d->resolve_references();
decode_eq_or_diff('PerlBool', $encoded_true, { bool_f => 1 });
decode_eq_or_diff('PerlBool', $encoded_false, { bool_f => '' });
decode_eq_or_diff('PerlBool', $encoded_default, { bool_f => '' });
}
{
my $d = Google::ProtocolBuffers::Dynamic->new('t/proto');
$d->load_file("bool.proto");
$d->map_message("test.Bool", "NumericBool", { explicit_defaults => 1, boolean_values => 'numeric', decode_blessed => 0 });
$d->resolve_references();
decode_eq_or_diff('NumericBool', $encoded_true, { bool_f => 1 });
decode_eq_or_diff('NumericBool', $encoded_false, { bool_f => 0 });
decode_eq_or_diff('NumericBool', $encoded_default, { bool_f => 0 });
}
SKIP: {
skip 'JSON module not installed' unless eval { require JSON; 1 };
my $d = Google::ProtocolBuffers::Dynamic->new('t/proto');
$d->load_file("bool.proto");
$d->map_message("test.Bool", "JSONBool", { explicit_defaults => 1, boolean_values => 'json', decode_blessed => 0 });
$d->map_message("test.OuterBool", "JSONOuterBool", { decode_blessed => 0 });
$d->resolve_references();
decode_eq_or_diff('JSONBool', $encoded_true, { bool_f => JSON::true() });
decode_eq_or_diff('JSONBool', $encoded_false, { bool_f => JSON::false() });
decode_eq_or_diff('JSONBool', $encoded_default, { bool_f => JSON::false() });
decode_eq_or_diff('JSONOuterBool', $encoded_outer, { bool => { bool_f => JSON::true() } }, 'correct mapper object is used during bool decoding');
}
{
my $d = Google::ProtocolBuffers::Dynamic->new('t/proto');
$d->load_file("bool.proto");
throws_ok(
sub { $d->map_message("test.Bool", "OopsBool", { boolean_values => 'nope' }) },
qr/Invalid value 'nope' for 'boolean_values' option/
);
}
done_testing();
t/301_boolean_accessors.t view on Meta::CPAN
use t::lib::Test;
my $encoded_true = "\x38\x01";
my $encoded_false = "\x38\x00";
my $encoded_default = "";
{
my $d = Google::ProtocolBuffers::Dynamic->new('t/proto');
$d->load_file("scalar.proto");
$d->map_message("test.Basic", "PerlBasic", { explicit_defaults => 1, boolean_values => 'perl' });
$d->resolve_references();
my $obj = PerlBasic->new;
is($obj->get_bool_f, '');
$obj->set_bool_f("a");
is($obj->get_bool_f, 1);
$obj->set_bool_f(0);
is($obj->get_bool_f, '');
}
{
my $d = Google::ProtocolBuffers::Dynamic->new('t/proto');
$d->load_file("scalar.proto");
$d->map_message("test.Basic", "NumericBasic", { explicit_defaults => 1, boolean_values => 'numeric' });
$d->resolve_references();
my $obj = NumericBasic->new;
is($obj->get_bool_f, 0);
$obj->set_bool_f("a");
is($obj->get_bool_f, 1);
$obj->set_bool_f('');
( run in 0.456 second using v1.01-cache-2.11-cpan-9ff20fc0ed8 )