Reputation: 5132
How can I make any struct object to include any fields which are not defined in struct itself. Eg.
struct Point {
1: required x i32
2: optional y i32
}
No, if someone passes z variable in struct also, it would pass. So, how can I make the struct to handle extra fields?
Upvotes: 0
Views: 355
Reputation: 13411
One key thing about Thrift is that the IDL defines everything in advance, so the generated code is very compact and to the point (and therefore fast). So in general, this is not possible by design.
It could be an option though to treat additional data as kind of a blob (textual or binary) and de/serialize them by some other means:
struct Point {
1: x i32
2: y i32
3: binary more_data
}
The more_data
field could be bits serialized by some other Thrift step, or it could be sth. completely different, like compressed JSON or whatever else suits most.
The clear downside of that approach is that you will need two steps for serialization and deserialization insterad of only one: You need one for the inner blob contents, and one for the outer Thrift capsule. Whether or not that is an issue re your use case - I can't tell you that.
Upvotes: 1