I want to use protocol buffers in an iOS project. I try not to turn the entire project into an Objective-C ++ fiasco, so I want to combine the protobuf C ++ classes into Objective-C. I have dozens of protobuf posts, and although I did it successfully one class at a time, ideally I would like to use inheritance to minimize duplicate code. I am new to Objective-C and I have not used what I knew little about C ++ for 10 years, so this was basically an upset exercise. The following is an example of how I wrapped one message.
The code
.proto:
message MessageA { optional string value = 1; }
MessageAWrapper.h:
MessageAWrapper.mm:
goal
There is a lot of code here that will be repeated dozens of times, in which the only option is the type of the wrapped class ( init , dealloc , serialize , fromString ), so ideally I would instead put it in the parent class ProtobufMesssage . Unfortunately, I was unable to get this to work because I cannot find a way for the parent class to know the class that its children use, which is required, for example, in init and fromString .
Things I Took
- structure
- class of patterns
- invalid *
Obstacles I faced
- can't find a way to store class / type reference
- cannot have headers or C ++ code in the .h file (since this requires the entire project to be Objective-C ++)
- the difficulty of storing links to parent protobuf messages (
Message or MessageLite ), because they are abstract
As I said, I have very little understanding of C ++ or Objective-C; most of my experience is related to much higher-level languages ββsuch as Python and Java (although I basically understand basic C things like pointers).
Perhaps this is not even possible? Am I approaching him incorrectly or do not see something obvious? Any help is appreciated. Thanks.
Derek source share