3

I am writing a generic SDK in which i am planning to use Protobuf (due to its advantages). I would have a generic header message as below

class Header
{
  string Id;
  Datetime Timestamp;
  string ProcessName; //This is the Process in my server
  string SessionID;
}

Now this message ideally would be inherited by an Application Message and write their own message. A pseudo code of the Application message would be

class Application : Header
{
  string AppId;
  string Message;
}

Now the implementation would be as below

Application appobj = new Application();
appobj.Id = "1";
appobj.Timestamp = DateTime.Now();
appobj.ProcessName = "ApplicationLog";
appobj.SessionId = "aaa-ee-rr"; //Guid
appobj.AppId = "App Logger";
appobj.Message = "Database";

Ideally when i get the message i would be only getting Application class proto (internally inheriting Header), the proto definition of which will not be present with me, as different applications would have their own proto. The server application would only have the proto message of the Header, which it should read and redirect to different Processes running on the server depending on the "Process Name".

Another consideration is the different processes are in c# but couple in Python. I saw both the protobuf-csharp-port and the Protbuf-net version (written by different people) and understood that for variety of programming languages being involved it is better to use the csharp-port than Protobuf-net version.

I have searched a lot on Stackoverflow and on the net, but i am unable to find a solution of getting the Header information from the application message without knowing the Application message proto (I only know Header proto which is inherited by the application).

adityaswami89
  • 573
  • 6
  • 15
  • Protocol buffers don't have inheritance. If you want to accept protocol buffers containing arbitrary data in proto 3, you can use the `Any` type. https://developers.google.com/protocol-buffers/docs/proto3#any – zstewart Dec 08 '16 at 05:49
  • As @zstewart already said, there is no inheritance in protobuf, however one can use extension mechanism to emulate it. See post http://www.indelible.org/ink/protobuf-polymorphism/ for explanation. –  Dec 09 '16 at 15:07
  • @BorisT Extensions are a Proto 2 feature, they were removed in Proto 3 in favor of the "Any" type. Both are mechanisms that allow you to include data of arbitrary other protos by embedding rather than inheritance. – zstewart Dec 09 '16 at 16:58
  • ok, i understand there is an extension feature, however will i be able to split only the base class information from the child class by only knowing the base class proto ? – adityaswami89 Dec 11 '16 at 06:13

0 Answers0