I have a thrift struct
struct Message {
1: optional int userID;
...
}
Is it a safe operation to change it to default require-ness?
struct Message {
1: int userID;
...
}
If I know it's always set? What about "required"?
I have a thrift struct
struct Message {
1: optional int userID;
...
}
Is it a safe operation to change it to default require-ness?
struct Message {
1: int userID;
...
}
If I know it's always set? What about "required"?
As outlined in this answer, there are three degrees of (so-called) requiredness in Thrift:
required
: must exist on read, must be set on writeoptional
: may or may not be set, entirely optionalnull
pointer )To answer the question(s) asked:
It is safe to change optional
to default (i.e. remove the optional
keyword).
Changing optional
to required
may break compatibility. Unless you make sure all clients/servers are updated accordingly, it may happen that the older side does not supply a value for such a field. In that case, the other end will reject the incoming request or response as incomplete, because that required
field is missing from the received data.
For further reading on the subject you may want to consult Diwaker Gupta's highly recommendable "Missing Guide".