breese / trial.protocol

Network wire protocols
11 stars 4 forks source link

Add json::partial::copy_and_look_ahead() #57

Open vinipsmaker opened 3 years ago

vinipsmaker commented 3 years ago

So... I'm so confident this function fills a gap that I went ahead and implemented it before we had the chance to exchange any message about the idea.

Updates #26

vinipsmaker commented 3 years ago

As an example of a protocol that requires to look ahead before we decide the C++ type to be deserialized to, check the BitMEX API: https://www.bitmex.com/app/wsAPI

Before we interpret any other members from the root object, we must check the "op" attribute.

TBH this example is actually not very good because better alternative serializations exist for this specific protocol. However that's a common pattern (an "id"/"type"/"MsgType" field to describe the type instance) and the example is just enough to illustrate this pattern. I'm just pasting literally the first WS API that popped up in my head. I'm not gonna really try to find a second/better example.