Issue with extends

Skip to first unread message

Geervani BS

Aug 3, 2021, 12:58:28 AMAug 3
to Protocol Buffers
Hello All,

I have a message as below:

message DynamicGroupPlot
  extend GroupPlot {
    optional DynamicGroupPlot plot = 100; 

  repeated int32 line = 1 
  optional bool overlay = 5;
  optional bool tdc_shift = 6;
  optional bool smoothing = 7;
  optional bool valve_events = 8;
  optional bool theoretical = 9;

I am using c# compiler. With extends what I understood is, it will create a mapping between DynamicGroupPlot and GroupPlot  i.e some kind of inheritance. But the generated .cs files doesn't show any relationship between  DynamicGroupPlot  and GroupPlot .

Here is the snippet from generated .cs file

 public sealed partial class DynamicGroupPlot : pb::IMessage<DynamicGroupPlot>
    public DynamicGroupPlot() {

    partial void OnConstruction();

    public DynamicGroupPlot(DynamicGroupPlot other) : this() {
      _hasBits0 = other._hasBits0;
      line_ = other.line_.Clone();
      dynamicType_ = other.dynamicType_;
      phasing_ = other.phasing_;
      autoscale_ = other.autoscale_;
      overlay_ = other.overlay_;
      tdcShift_ = other.tdcShift_;
      smoothing_ = other.smoothing_;
      valveEvents_ = other.valveEvents_;
      theoretical_ = other.theoretical_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);

I am new to protobuf. Any help is much appreciated.


Adam Cozzette

Aug 3, 2021, 9:07:00 AMAug 3
to Geervani BS, Protocol Buffers
Extensions are not quite like inheritance. The way I think of an extension is that it is like an ordinary field except with the dependency inverted, so that the field depends on the message rather than the message depending on the field.

I haven't worked with the C# implementation, but as I understand the generated code should include a static pb::Extension variable called Plot (or similar), which you can use to get or set the extension on a GroupPlot message. Here are some examples from the unit tests:

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
To view this discussion on the web visit
Reply all
Reply to author
0 new messages