- assert(len_val0 == sizeof(Count));
- assert(len_val1 == sizeof(Count));
-
- const Count* c0 = reinterpret_cast<const Count*>(val0);
- const Count* c1 = reinterpret_cast<const Count*>(val1);
- unique_ptr<Count> c((Count *)malloc(sizeof(Count))); // Needs to be with malloc, per merger spec.
-
- c->white = c0->white + c1->white;
- c->draw = c0->draw + c1->draw;
- c->black = c0->black + c1->black;
- c->sum_white_elo = c0->sum_white_elo + c1->sum_white_elo;
- c->sum_black_elo = c0->sum_black_elo + c1->sum_black_elo;
- c->num_elo = c0->num_elo + c1->num_elo;
- if (c0->first_timestamp <= c1->first_timestamp) {
- c->opening_num = c0->opening_num;
- c->first_timestamp = c0->first_timestamp;
- } else {
- c->opening_num = c1->opening_num;
- c->first_timestamp = c1->first_timestamp;
- }
+ Count c0, c1;
+ c0.ParseFromArray(val0, len_val0);
+ c1.ParseFromArray(val1, len_val1);
+
+ Count c = merge_count(c0, c1);
+
+ static string buf; // Keep allocated.
+ c.SerializeToString(&buf);