mbarbon / google-protobuf-dynamic

Fast and complete Perl protobuf implementation using uPB and Google .proto parser
35 stars 18 forks source link

Mapping message with external message dependencies #27

Closed edam closed 5 years ago

edam commented 5 years ago

Unless I'm missing something, there doesn't appear to be a very convenient method to map a message that uses message types defined in other packages.

E.g., suppose you have these two proto files:

a.proto:

syntax = "proto3";
package a;

import "b.proto";

message A {
    b.B foo = 1;
}

b.proto:

syntax = "proto3";
package b;

message B {
    string bar = 1;
}

And you wanted to map a.A, you might go as follows:

$dynamic->load_file( "a.proto" );
$dynamic->map( { message => 'a.A', to => 'PB' } );

But this raises the following error (actually from resolve_references()):

Unknown type 'b.B'

It may not always be convenient to map b.B first. For example, in the case where you are writing a generic tool, you may not know that you have to. It would be significantly more convenient to be able to load a message and map anything it needs to a perl package prefix.

edam commented 5 years ago

Just to elaborate... the issue with the regular map_message() function is that is uses the protocol buffers library's nested_type_count() and enum_type_count() to recursively map nested messages and enums. These do not include messages and enums in other packages.