obsproject / obs-websocket

Remote-control of OBS Studio through WebSocket
GNU General Public License v2.0
3.84k stars 704 forks source link

Feature Request: Send Op field before D field in messages from OBS to the Client #1061

Closed tinodo closed 1 year ago

tinodo commented 1 year ago

Feature Request Type

Other

Feature Request Type (Other)

For all messages sent from OBS: Send Op field before D field in messages from OBS to the Client

Requested Feature

It would be great if OBS would send the Op field before the D field. This would make deserialization of the messages a lot faster and easier. Since the Op field is the discriminating field, it identifies the content type of the D field, it would be highly beneficial to those that deserialize the message into the proper classes. Now, we have to temporarily store the D field in an object, just to see what it actually is later, when we get the Op field. Reversing the order would be great!

Requested Feature Usage Scenario

More information about this exact scenario are (for example) here: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/converters-how-to?source=recommendations&pivots=dotnet-6-0#support-polymorphic-deserialization

It would be beneficial to receive the Op field before the D field.

tinodo commented 1 year ago

This also goes for all other messages sent by OBS to the client; please send the Discriminator first.

tt2468 commented 1 year ago

In the source code, we do in-fact set elements in the order requested. However, as described in the msft documentation, objects in the JSON standard have no order guarantees. The JSON serializer we use (nlohmann) does what it wants.

If you're worried about deserialization speed, I would recommend using msgpack communication over JSON. I'm not sure of what order guarantees are made in msgpack relating to objects, but it may be serialized in-order there. See here for more info.