public Timestamp Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var token = reader.GetCurrentJsonToken(); if (token == JsonToken.String) { reader.AdvanceOffset(1); var asDecimal = formatterResolver.GetFormatterWithVerify <decimal>().Deserialize(ref reader, formatterResolver); // ReSharper disable once RedundantOverflowCheckingContext var timestamp = new Timestamp(checked ((long)(asDecimal * 1_000_000_000L))); reader.AdvanceOffset(1); return(timestamp); } if (token == JsonToken.Number) { var asDecimal = formatterResolver.GetFormatterWithVerify <decimal>().Deserialize(ref reader, formatterResolver); // ReSharper disable once RedundantOverflowCheckingContext var timestamp = new Timestamp(checked ((long)(asDecimal * 1_000_000_000L))); return(timestamp); } ThrowHelper.ThrowInvalidOperationException($"Wrong timestamp token in JSON: {token}"); return(default);
public T DeserializeFromPropertyName(JsonReader reader, IJsonFormatterResolver formatterResolver) { if (serializeByName) { return(Deserialize(reader, formatterResolver)); } else { var token = reader.GetCurrentJsonToken(); if (token != JsonToken.String) { throw new InvalidOperationException("Can't parse JSON to Enum format."); } reader.AdvanceOffset(1); // skip \"" var t = Deserialize(reader, formatterResolver); // token is Number reader.SkipWhiteSpace(); reader.AdvanceOffset(1); // skip \"" return(t); } }
public Timestamp Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var token = reader.GetCurrentJsonToken(); if (token == JsonToken.String) { // TODO check that current byte is " reader.AdvanceOffset(1); var timestamp = reader.ReadInt64(); reader.AdvanceOffset(1); return((Timestamp)timestamp); } if (token == JsonToken.Number) { var timestamp = reader.ReadInt64(); // TODO we could detect millis (all values are in jan 1971 as nanos) or micros (~<=1972) // But the problem is with deltas return((Timestamp)timestamp); } ThrowHelper.ThrowInvalidOperationException("Wrong timestamp token"); return(default);
protected override IAccountSetting DeserializeItem(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { int offset = reader.GetCurrentOffsetUnsafe(); // ServiceTypeを探す int count = 0; while (reader.ReadIsInObject(ref count)) { var propertyName = reader.ReadPropertyName(); if (propertyName == "service") { var serviceTypeValue = reader.ReadString(); if (!this._serviceNameMap.TryGetValue(serviceTypeValue, out var serviceType)) { throw new NotImplementedException(); } reader.AdvanceOffset(offset - reader.GetCurrentOffsetUnsafe()); switch (serviceType) { case ServiceType.Twitter: var twFormatter = formatterResolver.GetFormatter <TwitterAccountSetting>(); return(twFormatter.Deserialize(ref reader, formatterResolver)); case ServiceType.Mastodon: var mdFormatter = formatterResolver.GetFormatter <MastodonAccountSetting>(); return(mdFormatter.Deserialize(ref reader, formatterResolver)); default: throw new NotImplementedException(); } } Debug.WriteLine(propertyName); reader.ReadNextBlockSegment(); } throw new NotImplementedException(); }