billvaglienti / ProtoGen

Communications protocol generation software
MIT License
30 stars 16 forks source link

Externally defined structs? #71

Closed jefffisher closed 6 years ago

jefffisher commented 6 years ago

I have a protocol in which I'm trying to reference a struct defined by a different protocol. It nearly works, except the default behavior of ProtoGen when encountering a struct not defined in the XML file is to guess at an include file, which in this case does not exist:

https://github.com/billvaglienti/ProtoGen/blob/b0a161a459ca585c753f160c560694c1e358c87a/protocolfield.cpp#L1600-L1626

Is there any reason not to remove that behavior and treat them more like enums? For example:

    else if(inMemoryType.isStruct)
    {
        include = parser->lookUpIncludeName(typeName);
        if(!include.isEmpty())
            list.append(include);

    }// else if struct
billvaglienti commented 6 years ago

I think your suggestion is appropriate. The include name guess is a holdover from simpler days when it was expected that every structure would live in its own file with a name that was determined from the structure type name. I've made the requested changed, and it appears in 2.11.e. (I'm on the fence about whether this is a bug fix or a feature change).

It seems to me that a number of other problems will arise if ProtoGen cannot resolve a structure definition. You may want to look into the ability to have one protocol file depend on another. If (for example) you have one structure that you want to share between two protocols you could define that structure in its own XML, and then include it in the other protocol's xml (via xml attribute or command line) that want to reuse the structure.