Implement messages conversion #3
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Messages conversion
We need to convert JSON messages that we'll accept from the network <-> some sort of inner representation.
JSON format
Expected JSON messages will consist of (message_group, message_type, contents). For example:
As JSON it would look like this:
{"g":"db","t":"addi","c":{"var":"/player_id/headshots","inc":10}}
.Corresponding inner representation
Inner representation will be the enum with several options. Correspondence with JSON is as such:
So for db messages enum can look something like:
Implementation details
I propose extendable system that will provide a trait, that will mark
enum
s as inner message representation.This trait will require two methods for JSON <-> enum conversion.
Determining to which
enum
to conver JSON will be based on specified message group, thenenum
decides which option to pick based on specified message type and parses contents into it's parameters.Message converter
To allow having several message enums (message groups) in an extendable manner, we will need to introduce a separate message converter object that will somehow encapsulate String<->enum 1-to-1 mapping, that will link a group name to corresponding message enum.
Since it will contain part of information necessary for conversion, it will also provide a facade for actually converting messages.
Workflow would ge similar to this:
Messages conversionto Implement messages conversionUpon further consideration and prototyping, I don't feel that described system will help at all, - even supposing most general requirements for avarice. Therefore, this idea is scrapped.