I worked on a very small program to get information about Half Life 2 servers (using the protocol-srcds library ). The workflow is pretty simple; it takes a list of servers from a file, requests each of them and writes the output to another file (which is read by a PHP script to display, since I am attached to vBulletin). It would be nice if it were done in SQL or something like that, but seeing that I'm still just learning, this step is too far now!
In any case, my question is about serialization, namely serialization in JSON. At the moment, I wrote a scrappy helper jsonify , such that:
jsonify (Just (SRCDS.GameServerInfo serverVersion serverName serverMap serverMod serverModDesc serverAppId serverPlayers serverMaxPlayers serverBots serverType serverOS serverPassword serverSecure serverGameVersioning)) = toJSObject [ ("serverName", serverName) , ("serverMap", serverMap) , ("serverPlayers", show serverPlayers) , ("serverMaxPlayers", show serverMaxPlayers) ]
(I am using the Text.JSON package). This is obviously not perfect. At this point, however, I don’t understand how to use instances to define serializers for records, and my attempts to do this met a wall of frustration with the type system.
Can someone please guide me through the “right” way to do this? How can I define an instance that serializes a record? What functions should be used in instance (showJSON?).
Thanks in advance for your help.
source share