private static ServerInformationComplete[] DeserializeFast(Stream stream) { var reader = new JsonTextReader(new StreamReader(stream)); var response = new List <ServerInformationComplete>(AverageServersCount); var currentProperty = string.Empty; reader.MatchNext(JsonToken.StartArray); while (reader.IsMatchNext(JsonToken.StartObject)) { var entry = new ServerInformationComplete(); while (reader.Until(JsonToken.EndObject)) { SetToken(reader, ref currentProperty, entry); } response.Add(entry); } return(response.ToArray()); }
protected static bool SetToken(JsonTextReader reader, ref string currentProperty, ServerInformationComplete entry) { switch (reader.TokenType) { case JsonToken.PropertyName: currentProperty = reader.Value.ToString(); return(true); case JsonToken.String: switch (currentProperty) { case "ip": entry.Ip = reader.Value.ToString(); return(true); case "name": entry.Name = reader.Value.ToString(); return(true); case "track": entry.TrackId = reader.Value.ToString(); return(true); } break; case JsonToken.Integer: switch (currentProperty) { case "port": entry.Port = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "cport": entry.PortHttp = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "tport": entry.PortRace = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "clients": entry.Clients = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "maxclients": entry.Capacity = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "timeofday": entry.Time = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "session": entry.Session = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "timeleft": entry.TimeLeft = long.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "timestamp": entry.Timestamp = long.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "lastupdate": entry.LastUpdate = long.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); case "inverted": entry.Inverted = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return(true); } break; case JsonToken.Boolean: switch (currentProperty) { case "pass": entry.Password = bool.Parse(reader.Value.ToString()); return(true); case "pickup": entry.PickUp = bool.Parse(reader.Value.ToString()); return(true); case "timed": entry.Timed = bool.Parse(reader.Value.ToString()); return(true); case "extra": entry.Extra = bool.Parse(reader.Value.ToString()); return(true); case "inverted": entry.Inverted = bool.Parse(reader.Value.ToString()) ? -1 : 0; return(true); case "l": #pragma warning disable 612 entry.Lan = bool.Parse(reader.Value.ToString()); #pragma warning restore 612 return(true); } break; case JsonToken.StartArray: switch (currentProperty) { case "cars": entry.CarIds = reader.ReadStringArray(1); return(true); case "sessiontypes": entry.SessionTypes = reader.ReadIntArray(1); return(true); case "durations": entry.Durations = reader.ReadLongArray(1); return(true); case "country": entry.Country = reader.ReadStringArray(2); return(true); default: while (reader.Until(JsonToken.EndArray)) { } return(true); } case JsonToken.Null: break; default: throw new Exception("Unexpected token: " + reader.TokenType); } return(false); }