Hi,

My environment is proto2/Linux/Windows/c++ but I think this should be 
generic across all.

What I want to achieve is to take deltas of messages, transfer them across 
network, and apply the deltas on the receiving ends so that data objects 
are synchronized without costing a lot of bandwidth. Say I have an object 
with 100 fields and I only change a few of them at a time.

I initially did it using MessageDifferencer to compare the "from" and "to" 
message and Reporter to catch the changes. I record the Add/Changed/Deleted 
fields and put them into a pair of google.protobuf.FieldMask, one for 
add/change, the other for delete. Nested messages will have dot separated 
paths as the way FieldMaskUtil manipulates paths. I then create a blank 
message and MergeMessageTo() from the "to" message to create the delta. For 
the repeated fields and map fields I don't record the details and will just 
put the whole thing in the delta. So when I send out the delta I send out 2 
separated frames, one with the delta message and the other with the masks.

This approach does work but it has 2 issues. Firstly the overhead is 
significant if messages are small. For data objects smaller than 100bytes 
it's probably not worth the effort. The masks are in strings and I 
understand it's the price to pay. The other issue is it's really slow. 
Depending on the situation, during my test it's hundreds of times slower to 
do a diff and apply than just make a copy. To compare I tried report to 
string and it's even slower.

Currently I'm trying the alternative, which was put into the "too hard" 
basket earlier. I'm trying to create a wrapper of the message and delegate 
all mutating operations so that I can track all changes. It seems possible 
but the code looks painfully clumsy. There will be large switch cases for 
all the data types with almost identical code. The template SetField() in 
Reflection is not even available for public use.

So my question is, am I in the right direction? Or is there a better way?

Thanks,
Lei

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/dd3ed3e4-4608-46f6-aa61-9ac6770f3eb8n%40googlegroups.com.

Reply via email to