public static bool Parse(ref JsonReader reader, ref DtoPremium dto) { if (!reader.ReadIsBeginObject()) { return(false); } var propName = reader.ReadPropertyNameSegmentRaw(); if (propName.EqualTo(s_start)) { dto.start = reader.ReadInt32(); } else if (propName.EqualTo(s_finish)) { dto.finish = reader.ReadInt32(); } else { return(false); } if (!reader.ReadIsValueSeparator()) { return(false); } propName = reader.ReadPropertyNameSegmentRaw(); if (propName.EqualTo(s_start)) { dto.start = reader.ReadInt32(); } else if (propName.EqualTo(s_finish)) { dto.finish = reader.ReadInt32(); } else { return(false); } if (!reader.ReadIsEndObject()) { return(false); } return(true); }
// using low-level to catch wrong structure or properties // ids and likes are internalized public static bool Parse(ref JsonReader reader, DtoAccount dto, Storage store) { var count = 0; if (reader.ReadIsNull() || !reader.ReadIsBeginObject()) { return(false); } while (true) { var prop = reader.ReadPropertyNameSegmentRaw(); // id if (prop.EqualTo(s_id)) { if (reader.GetCurrentJsonToken() != JsonToken.Number) { return(false); } dto.id = Mapper.ExtIdToIntIdCreate(reader.ReadInt32()); dto.flags |= DtoFlags.Id; } else // status if (prop.EqualTo(s_status)) { var st = new AString(reader.ReadStringSegmentRaw()).InPlaceUnescape(); if (st == s_Free) { dto.status = STATUS_FREE; } else if (st == s_Taken) { dto.status = STATUS_TAKEN; } else if (st == s_Complicated) { dto.status = STATUS_COMPLICATED; } else { return(false); } dto.flags |= DtoFlags.Status; } else // sex if (prop.EqualTo(s_sex)) { var st = reader.ReadStringSegmentRaw(); if (st.EqualTo(s_male)) { dto.sex = SEX_MALE; } else if (st.EqualTo(s_female)) { dto.sex = SEX_FEMALE; } else { return(false); } dto.flags |= DtoFlags.Sex; } else // email if (prop.EqualTo(s_email)) { dto.email = reader.ReadStringSegmentRaw(); dto.flags |= DtoFlags.Email; } else // phone if (prop.EqualTo(s_phone)) { dto.phone = new AString(reader.ReadStringSegmentRaw()).Duplicate(); dto.flags |= DtoFlags.Phone; } else // fname if (prop.EqualTo(s_fname)) { dto.fnameIdx = (short)store.Fnames.GetOrCreateRange( new AString(reader.ReadStringSegmentRaw()).InPlaceUnescape()).Index; dto.flags |= DtoFlags.Fname; } else // sname if (prop.EqualTo(s_sname)) { dto.snameIdx = (short)store.Snames.GetOrCreateRange( new AString(reader.ReadStringSegmentRaw()).InPlaceUnescape()).Index; dto.flags |= DtoFlags.Sname; } else // country if (prop.EqualTo(s_country)) { dto.countryIdx = (byte)store.Countries.GetOrCreateRange( new AString(reader.ReadStringSegmentRaw()).InPlaceUnescape()).Index; dto.flags |= DtoFlags.Country; } else // city if (prop.EqualTo(s_city)) { dto.cityIdx = (short)store.Cities.GetOrCreateRange( new AString(reader.ReadStringSegmentRaw()).InPlaceUnescape()).Index; dto.flags |= DtoFlags.City; } else // birth if (prop.EqualTo(s_birth)) { if (reader.GetCurrentJsonToken() != JsonToken.Number) { return(false); } dto.birth = reader.ReadInt32(); dto.flags |= DtoFlags.Birth; } else // joined if (prop.EqualTo(s_joined)) { if (reader.GetCurrentJsonToken() != JsonToken.Number) { return(false); } dto.joined = reader.ReadInt32(); dto.flags |= DtoFlags.Joined; } else // premium if (prop.EqualTo(s_premium)) { if (!DtoPremium.Parse(ref reader, ref dto.premium)) { return(false); } dto.flags |= DtoFlags.Premium; } else // interests if (prop.EqualTo(s_interests)) { if (!reader.ReadIsBeginArray()) { return(false); } while (!reader.ReadIsEndArrayWithSkipValueSeparator(ref count)) { dto.interests.Set(store.Interests.GetOrCreateRange(new AString(reader.ReadStringSegmentRaw()).InPlaceUnescape()).Index); } dto.flags |= DtoFlags.Interests; } else // likes if (prop.EqualTo(s_likes)) { if (!reader.ReadIsBeginArray()) { return(false); } // read likes if (reader.GetCurrentJsonToken() == JsonToken.BeginObject) { while (true) { Like like = new Like(); if (!reader.ReadIsBeginObject()) { return(false); } while (true) { var propName = reader.ReadPropertyNameSegmentRaw(); if (propName[0] == (byte)'t') // ts { if (reader.GetCurrentJsonToken() != JsonToken.Number) { return(false); } like.ts = Like.ExtToIntTS(reader.ReadInt32()); } else if (propName[0] == (byte)'i') // id { if (reader.GetCurrentJsonToken() != JsonToken.Number) { return(false); } if (!Mapper.ExtIdToIntId(reader.ReadInt32(), out like.id)) { return(false); } } else // not ts nor id { return(false); } if (!reader.ReadIsValueSeparator()) { break; } } if (!reader.ReadIsEndObject()) { return(false); } dto.likes.Add(like); if (!reader.ReadIsValueSeparator()) { break; } } } if (!reader.ReadIsEndArray()) { return(false); } dto.flags |= DtoFlags.Likes; } else { return(false); } if (!reader.ReadIsValueSeparator()) { break; } } if (!reader.ReadIsEndObject()) { return(false); } return(true); }