Search code examples
protocol-buffers

Need to modify type of field for protobuf


I have quick question for modifying type of field for protobuf. I have create the int64 id something like below.

message test {
    int64 id = 1;
}

And I find out I can not set this id as null because of the type. Therefore, I would like to modify it from int64 to int64value but do not sure is there any standard way for this kind of operation.

message test {
    // int64 id = 1;
    int64value id = 2;
}

or

message test {
    int64 id = 1 [deprecated=true];
    int64value id = 2;
}

Thanks and open to any kind of input!

I would like to get more standard way for this kind of operation.


Solution

  • You can reference values by field number or by name. So your first approach works. As long as you do not need backwards compatibility you could just change the id from int to your id type. This would result in a cleaner code.

    For the use of the deprecated Attribut you could check out this:

    Google protobuf 3: deprecated a field, but cannot remove the dependencies?