/// <summary> /// Enumerates records from a stream in the Naiad serialization format. /// </summary> /// <typeparam name="TRecord">Type of record in the stream</typeparam> /// <param name="stream">A stream containing records serialized in the Naiad messaging format</param> /// <returns>An enumeration of records in the stream</returns> public static IEnumerable <TRecord> GetNaiadReaderEnumerable <TRecord>(System.IO.Stream stream) { using (NaiadReader <TRecord> reader = new NaiadReader <TRecord>(stream)) { TRecord nextElement; while (reader.TryRead(out nextElement)) { yield return(nextElement); } } }
/// <summary> /// Enumerates records from a stream in the Naiad serialization format. /// </summary> /// <typeparam name="TRecord">Type of record in the stream</typeparam> /// <param name="stream">A stream containing records serialized in the Naiad messaging format</param> /// <param name="codeGenerator">code generator</param> /// <returns>An enumeration of records in the stream</returns> internal static IEnumerable <TRecord> GetNaiadReaderEnumerable <TRecord>(System.IO.Stream stream, SerializationFormat codeGenerator) { NaiadReader reader = new NaiadReader(stream, codeGenerator); NaiadSerialization <TRecord> deserializer = codeGenerator.GetSerializer <TRecord>(); TRecord nextElement; while (reader.TryRead <TRecord>(deserializer, out nextElement)) { yield return(nextElement); } }
/// <summary> /// Enumerates batches of records from a stream in the Naiad serialization format. /// </summary> /// <typeparam name="TRecord">Type of record in the stream</typeparam> /// <param name="stream">A stream containing records serialized in the Naiad messaging format</param> /// <param name="batchSize">number of records per batch</param> /// <returns>An enumeration of records in the stream</returns> public static IEnumerable <ArraySegment <TRecord> > GetNaiadReaderBatchEnumerable <TRecord>( System.IO.Stream stream, int batchSize) { using (NaiadReader <TRecord> reader = new NaiadReader <TRecord>(stream)) { int batchIndex; do { TRecord[] batch = new TRecord[batchSize]; for (batchIndex = 0; batchIndex < batchSize; ++batchIndex) { if (!reader.TryRead(out batch[batchIndex])) { break; } } if (batchIndex > 0) { yield return(new ArraySegment <TRecord>(batch, 0, batchIndex)); } } while (batchIndex == batchSize); } }