Issue with extends

12 views
Skip to first unread message

Geervani BS

unread,
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>
  
  {
 .
.
.
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    public DynamicGroupPlot() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    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.


Regards
Geervani

Adam Cozzette

unread,
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: https://github.com/protocolbuffers/protobuf/blob/d13afed5639727c3c52d302ddfb3a0a04e21eb74/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs#L116

--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/77c427d5-624e-4de5-a32d-031e5e97e7c2n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages