I created a very simple patch for perlxs_generator.cc (attached). It adds a
'fields' method. This method returns the names of all fields defined in the
message. I need it for a project I'm working on and the API doesn't seem to
support reflection.
My perl XS skills are pretty weak so criticisms are welcome.
--
seth /\ sethdaniel.org
Index: src/google/protobuf/compiler/perlxs/perlxs_generator.cc
===================================================================
--- src/google/protobuf/compiler/perlxs/perlxs_generator.cc (revision 11)
+++ src/google/protobuf/compiler/perlxs/perlxs_generator.cc (working copy)
@@ -342,6 +342,10 @@
"=item B<$length = $*value*-E<gt>length()>\n"
"\n"
"Returns the serialized length of C<*value*>.\n"
+ "\n"
+ "=item B<@fields = $*value*-E<gt>fields()>\n"
+ "\n"
+ "Returns the defined fields of C<*value*>.\n"
"\n");
// Message field accessors
@@ -1057,6 +1061,24 @@
" RETVAL\n"
"\n"
"\n");
+
+ // Fields
+
+ printer.Print(vars,
+ "int\n"
+ "$classname$::fields()\n"
+ " PPCODE:\n"
+ );
+ for ( int i = 0; i < descriptor->field_count(); i++ ) {
+ const FieldDescriptor* field = descriptor->field(i);
+ vars["field"] = field->name();
+ printer.Print(vars,
+ " XPUSHs(sv_2mortal(newSVpv(\"$field$\\0\",0)));\n"
+ );
+ }
+ printer.Print(vars,
+ "\n"
+ "\n");
}
Thanks. :o)
Can you elaborate on what you are adding?
--
seth /\ sethdaniel.org