protobuf-net / protobuf-net.Grpc

GRPC bindings for protobuf-net and grpc-dotnet
Other
846 stars 106 forks source link

ImplicitFields.AllPublic, the member order is alphabet? #309

Closed Roy-se7en closed 9 months ago

Roy-se7en commented 9 months ago
    [ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
    public class OutPut{

        public string Code { get; set; }

        public string Message { get; set; }

        public string Data { get; set; }
    }
message  OutPut{
  string Code = 1;
  string Data = 2;
  string Message = 3;
}

if i add member 'Body', such as

    [ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
    public class OutPut{

        public string Code { get; set; }

        public string Message { get; set; }

        public string Data { get; set; }

        public string Body { get; set; }
    }
message  OutPut{
  string Body = 1;
  string Code = 2;
  string Data = 3;
  string Message = 4;
}

if i upgrade the server code only ,the client(old version) occur error. is there any other setting of the order?

if the member order is below, it is compatible to the old version client

message  OutPut{
  string Code = 1;
  string Message = 2;
  string Data = 3;
}

then add member after member Data

message  OutPut{
  string Code = 1;
  string Message = 2;
  string Data = 3;
  string Body = 4;
}
mgravell commented 9 months ago

The intellisense comments should say, but: yes, alphabetical and yes adding members can be contract breaking. You can avoid problems by manually annotating it starting alphabetically, and then adding new.

https://github.com/protobuf-net/protobuf-net/blob/ae84aba11942eb45d261316a966c811bac8565b3/src/protobuf-net.Core/ImplicitFields.cs#L4

On Tue, 19 Sept 2023, 02:41 Roy-se7en, @.***> wrote:

[ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
public class OutPut{

    public string Code { get; set; }

    public string Message { get; set; }

    public string Data { get; set; }
}

message OutPut{ string Code = 1; string Data = 2; string Message = 3; }

if i add member 'Body', such as

[ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
public class OutPut{

    public string Code { get; set; }

    public string Message { get; set; }

    public string Data { get; set; }

    public string Body { get; set; }
}

message OutPut{ string Body = 1; string Code = 2; string Data = 3; string Message = 4; }

if i upgrade the server code only ,the client(old version) occur error. is there any other setting of the order?

if the member order is below, it is compatible to the old version client

message OutPut{ string Code = 1; string Message = 2; string Data = 3; }

then add member after member Data

message OutPut{ string Code = 1; string Message = 2; string Data = 3; string Body = 4; }

— Reply to this email directly, view it on GitHub https://github.com/protobuf-net/protobuf-net.Grpc/issues/309 or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEHMA6D4B6MEM6EY2WHR3X3DZ4TBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJLJONZXKZNENZQW2ZNLORUHEZLBMRPXI6LQMWBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTLDTOVRGUZLDORPXI6LQMWSUS43TOVS2M5DPOBUWG44SQKSHI6LQMWVHEZLQN5ZWS5DPOJ42K5TBNR2WLKJRHEZDEMZUHA4TPAVEOR4XAZNFNFZXG5LFUV3GC3DVMWVDCOJQGIYDKNBQGI2KO5DSNFTWOZLSUZRXEZLBORSQ . You are receiving this email because you are subscribed to this thread.

Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

Roy-se7en commented 9 months ago

Thank you for your reply!