public ReaderStatus ReadToObject <TObject>(ReaderState state, ILookupNode <char, ReaderCallback <ReaderState, RawProtobufValue, char, TObject> > root, ref TObject target) { if (!state.ObjectBegin(out var backup)) { return(state.TrySkipValue() ? ReaderStatus.Succeeded : ReaderStatus.Failed); } while (true) { state.ReadHeader(); // Stop reading complex object when no more field can be read if (state.FieldIndex <= 0) { state.ObjectEnd(backup); return(ReaderStatus.Succeeded); } var node = root.Follow('_'); if (state.FieldIndex > 9) { foreach (var digit in state.FieldIndex.ToString(CultureInfo.InvariantCulture)) { node = node.Follow(digit); } } else { node = node.Follow((char)('0' + state.FieldIndex)); } if (!(node.HasValue ? node.Value(this, state, ref target) == ReaderStatus.Succeeded : state.TrySkipValue())) { return(ReaderStatus.Failed); } } }
private ReaderStatus ReadToObjectFromArray <TObject>(ReaderState state, ILookupNode <int, ReaderCallback <ReaderState, JSONValue, int, TObject> > root, ref TObject target) { state.Read(); for (var index = 0;; ++index) { state.PullIgnored(); if (state.Current == ']') { break; } // Read comma separator if any if (index > 0) { if (!state.PullExpected(',')) { return(ReaderStatus.Failed); } state.PullIgnored(); } // Build and move to array index var node = root.Follow(index); // Read array value if (!(node.HasValue ? node.Value(this, state, ref target) != ReaderStatus.Failed : this.Skip(state))) { return(ReaderStatus.Failed); } } state.Read(); return(ReaderStatus.Succeeded); }