breese / trial.protocol

Network wire protocols
11 stars 4 forks source link

Merged matching & decode on Boost.Hana serialization #56

Open vinipsmaker opened 3 years ago

vinipsmaker commented 3 years ago

I know Boost.Hana serialization code wasn't merged yet. The issue is a future TODO item. I'll tackle it myself. And I don't want to keep my mind busy with this information. So I'll just dump the idea here and get back to it at some point in the future.

So I previously suggested the idea to optionally merge matching/decode phases (for string values only): https://github.com/breese/trial.protocol/issues/44#issuecomment-689552403. Once the feature hits the repo, I can update the Boost.Hana serialization code to make use of it.

The idea is: when I hit a member for which a std::string value is desired, branch the algorithm on:

struct_str_member.capacity() == 0

Do not merge matching/decode steps. Perform a separate match to get the literal() size and reserve enough data in one step. Then collect the string.

struct_str_member.capacity() != 0

Trust the user's size estimate heuristic and just merge matching/decode steps.