Clients with the old binary will not be able to read messages containing the
new enum value. This would get treated as an unknown field, meaning that the
type field would not be sent in an older client. Since your field is also
required, it would fail to parse. So, with this example, you would need to
make sure that all clients are updated before sending messages containing
the enum value.

The solution would be to use optional fields, and define an UNKNOWN enum
value.

e.g.:

enum Type { POP = 0, PUSH = 1, UNKNOWN = 2 }  // set unknown = 2 for
backward compatibility, assuming POP and PUSH are already defined and in the
wild.
message Command {
  optional Type type = 1 [default = UNKNOWN];
  ...
}

When you add TOP, you can start sending messages with that value before all
clients are updated. The message will now parse successfully on old clients,
who will get UNKNOWN when they access type().

On Fri, May 14, 2010 at 3:07 PM, john mani <john.m...@gmail.com> wrote:

> Hi
>
> This is my first attempt at  defining a command pattern :
>  message Command {
>   required Type type = 1;
>   optional Value value = 2;
>   optional Push push = 3;
>   optional Pop pop = 4;
>  }
>
>  enum Type { POP = 0, PUSH = 1 }
>
> I deploy code using this file.
>
> Later, I want to add a new command, but not break deployed clients.
> Can I do so safely:
>
>  enum Type { POP = 0, PUSH = 1, TOP = 2 }
>  message Command {
>   required Type type = 1;
>   optional Value value = 2;
>   optional Push push = 3;
>   optional Pop pop = 4;
>   optional Top top = 5;
>  }
>
> If not, what's the suggested way for achieving something like this?
> I read up on 'extend' - would that be a better way? My concern is that
> the other language ports (The C one, for example) do not yet support
> extend.
>
> thanx
> -john
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to