chaokunyang commented on PR #1413:
URL: https://github.com/apache/incubator-fury/pull/1413#issuecomment-2016342416
I updated the implementation guide, the implementation for static languages
can use `switch/jump` for type evolution deserialization:
- Assume current type has `n` fields, peer type has `n1` fields.
- Generate an auto growing `field id` from `0` for every sorted field in
current type at the compile time.
- Compare the received type meta with current type, generate same id if the
field name is same, otherwise generate an
auto growing id starting from `n`, cache this meta at runtime.
- Iterate the fields of received type meta, use a `switch` to compare the
`field id` to deserialize data
and `assign/skip` field value. **Continuous** field id will be optimized
into `jump` in `switch` block, so it will
very fast.
Here is an example, suppose process A has a class `Foo` with version 1
defined as `Foo1`, process B has a class `Foo`
with version 2 defined as `Foo2`:
```c++
// class Foo with version 1
class Foo1 {
int32_t v1; // id 0
std::string v2; // id 1
}
// class Foo with version 2
class Foo2 {
// id 0, but will have id 2 in process A
bool v0;
// id 1, but will have id 0 in process A
int32_t v1;
// id 2, but will have id 3 in process A
int64_t long_value;
// id 3, but will have id 1 in process A
std::string v2;
// id 4, but will have id 4 in process A
std::vector<std::string> list;
}
```
When process A received serialized `Foo2` from process B, here is how it
deserialize the data:
```c++
Foo1 &foo1 = xxx;
std::vector<fury::FieldInfo> &field_infos = type_meta.field_infos;
for (auto &field_info : field_infos) {
switch (field_info.field_id) {
case 0:
foo1.v1 = buffer.read_varint32();
break;
case 1:
foo1.v2 = fury.read_string();
break;
default:
fury.skip_data(field_info);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]