Hi Sergey, Protocol Buffers have an extension capability which is similar to what you are describing. The way to describe this in a .proto file would be something like:
syntax = "proto2"; message ChatMessage { optional string message = 1; extensions 100 to 200; } // These definitions can be in the same .proto file or a different one. extend ChatMessage { optional string hint = 100; } extend ChatMessage { optional string alert = 101; } You can read more about extensions here: https://developers.google.com/protocol-buffers/docs/proto?hl=en#extensions And the Java API for them is described here: https://developers.google.com/protocol-buffers/docs/reference/java-generated#extension Josh On Friday, January 22, 2016 at 9:54:44 AM UTC-8, Sergey K wrote: > > Hi! > How can I convert a ChatMessage to a proto message? > > //Need covert to proto message > public class ChatMessage { > private String message; > private List<Extension> extensions; > } > > interface Extension { > getName(); > } > > public abstract class AbstractExtension implement Extension { > > private String name; > public String getName() { return name;} > } > > public class HelpExtension extends AbstractExtension { > private String hint; > } > > public class AlertExtension extends AbstractExtension { > private String alert; > } > > ... and more implemented Extension class. > > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscr...@googlegroups.com. To post to this group, send email to protobuf@googlegroups.com. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.