Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross platform backwards compatibility #142

Open
staticgears opened this issue Jun 17, 2016 · 0 comments
Open

Cross platform backwards compatibility #142

staticgears opened this issue Jun 17, 2016 · 0 comments

Comments

@staticgears
Copy link

Version of protoc (protoc --version)

libprotoc 3.0.0

Version of ProtocolBuffers.framework

ProtoBuf3.0-Swift2.0 19ac094

.proto file to reproduce

syntax = "proto3";
package protocol;

import 'src/main/swift/swift-descriptor.proto';
option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities;

message Envelope {
    enum Type {
        CONTENT          = 0;
       //Added in a second version of the protocol
        READ                 = 1;
   }
}

Description

Protobuf 3 enum compatibility

Your implementation differs from the Java implementation in the following two key ways

  1. The protoc java implementation generates an UNKNOWN value for enums and when ever an unknown type is encountered the resulting Object has this UNKNOWN value for the enum.
  2. The protoc java implementation does not write out default values

The result of these two differences is that if I have a Swift client built using the first version of the protocol (ie without the READ value) and it receives a message from a Java client which sent the READ value that is indistinguishable from the case in which the Java client sends the CONTENT value.

It is worth noting that if all of the clients involved are using your Swift generator this ambiguity does not arise because the sender will write out the actual CONTENT value in the bytes (as opposed to the Java implementation which sends empty bytes and relies on the default object on the other side).The receiver can use the generated hasType property to differentiate the two cases if the full bytes are written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant