public static void handle(JsonParser parser, JsonMessageHandler[] handlers) { parser.skipDelimiter('{'); string key; parser.readKeyFromJson(out key); if (key != "msgid") { throw new Exception(); // bad format } ulong msgID; parser.parseUnsignedInteger(out msgID); parser.skipSpacesEtc(); parser.skipDelimiter(','); parser.readKeyFromJson(out key); if (key != "msgbody") { throw new Exception(); // bad format } JsonMessageHandler handler = find_handler(msgID, handlers); if (handler != null) { handler._delegate(parser, msgID); //parser.skipDelimiter('}'); } else { throw new Exception(); } }
static JsonMessageHandler find_handler(ulong msgID, JsonMessageHandler[] handlers) { // TODO improve JsonMessageHandler defaultHandler = null; for (int i = 0; i != handlers.Length; ++i) { if (msgID == handlers[i].msgID) { return(handlers[i]); } else if (handlers[i].msgID == JsonMessageHandler.DefaultHandler) { defaultHandler = handlers[i]; } } return(defaultHandler); }