Stephen
Stephen

Reputation: 621

protobuf backward compatibility

The following is overly simplified version of my protobuf messages:

message Item {
  string attribute0 = 1;
}

message Group {
  string name = 1;
  repeated Item = 2;  
}

And, a quite sizable software has been already implemented and running, using the protobuf message. The messages are sent by a client tool and consumed by the server.

I am about to update the server, and release a new client. The thing is that we still have to support the old client; the old client should be able to send the messages to the new server, and get the same result from the server.

And, I am planning to add fields to Item. Would it break compatibility with Group? My understanding is that as long as I do not change old numberings in Item and add optional fields only, the client sending Item will still work. However, what if the client was sending Group? Is Item now regarded as a different type so effectively the type of one field inside Group changed?

Upvotes: 2

Views: 4753

Answers (1)

jpa
jpa

Reputation: 12176

And, I am planning to add fields to Item. Would it break compatibility with Group? My understanding is that as long as I do not change old numberings in Item and add optional fields only, the client sending Item will still work.

That is correct.

However, what if the client was sending Group? Is Item now regarded as a different type so effectively the type of one field inside Group changed?

Protobuf has no concept of types in the encoded data, it has only tag numbers. You could change the names of your types to entirely different, as long as the tag numbers in both messages stay the same.

Upvotes: 1

Related Questions