public void Read(BionReader reader) { reader.Read(BionToken.StartArray); reader.Read(BionToken.Integer); int wordCount = (int)reader.CurrentInteger(); Words.Clear(); Index.Clear(); Indexed = false; while (true) { reader.Read(); if (reader.TokenType == BionToken.EndArray) { break; } // NOTE: Not copying word. Must use a 'ReadAll' BufferedReader reader.Expect(BionToken.String); String8 value = reader.CurrentString8(); reader.Read(BionToken.Integer); int count = (int)reader.CurrentInteger(); // Add to List, but not Index. Index will be populated when first needed. Words.Add(value); Counts.Add(count); } // Set capacity exact to save RAM Words.SetCapacity(Words.LengthBytes); }
public Region2 DeserializeRegion2(BionReader reader) { Region2 result = new Region2(); Expect(reader, BionToken.StartObject, "Region2"); while (reader.TokenType == BionToken.PropertyName) { String8 propertyName = reader.CurrentString8(); if (!classFieldParsers.TryGetValue(propertyName, out Action <BionReader, Region2> parser)) { throw new NotImplementedException($"Unknown property Region.{propertyName}. Stopping."); } reader.Read(); parser(reader, result); reader.Read(); } Expect(reader, BionToken.EndObject, "Region2"); return(result); }
private void WriteRunSubsetStart(JsonTextWriter writer) { int depth = _bionReader.Depth; // Read and copy everything in the run until the end object except the large collections while (_bionReader.Read() && _bionReader.Depth > depth) { if (_bionReader.TokenType == BionToken.PropertyName) { String8 propertyName = _bionReader.CurrentString8(); if (propertyName.Equals(Files) || propertyName.Equals(Results)) { _bionReader.Skip(); continue; } } JsonBionConverter.WriteToken(_bionReader, writer); } // Start a results array and leave open writer.WritePropertyName("results"); writer.WriteStartArray(); }
private static void Read(string filePath, string fromDictionaryPath) { VerifyFileExists(filePath); VerifyFileExists(fromDictionaryPath); long tokenCount = 0; using (new ConsoleWatch($"Reading [Full] {filePath} ({FileLength.MB(filePath)})...", () => $"Done; {tokenCount:n0} tokens found in file")) { if (filePath.EndsWith(".bion", StringComparison.OrdinalIgnoreCase)) { using (WordCompressor compressor = (fromDictionaryPath == null ? null : WordCompressor.OpenRead(fromDictionaryPath))) using (BionReader reader = new BionReader(File.OpenRead(filePath), compressor: compressor)) { while (reader.Read()) { tokenCount++; switch (reader.TokenType) { case BionToken.PropertyName: case BionToken.String: String8 value8 = reader.CurrentString8(); //string valueS = reader.CurrentString(); break; case BionToken.Integer: long valueI = reader.CurrentInteger(); break; case BionToken.Float: double valueF = reader.CurrentFloat(); break; } } } } else { using (JsonTextReader reader = new JsonTextReader(new StreamReader(filePath))) { while (reader.Read()) { tokenCount++; switch (reader.TokenType) { case JsonToken.PropertyName: case JsonToken.String: string valueS = (string)reader.Value; break; case JsonToken.Integer: long valueI = (long)reader.Value; break; case JsonToken.Float: double valueF = (double)reader.Value; break; } } } } } }