Beispiel #1
0
        /// <summary>
        /// Read the entire group into memory, then parse all the records.
        /// </summary>
        /// <param name="groupRef"></param>
        /// <returns></returns>
        public async Task <Result> ReadGroupBytes(Result.GroupRef groupRef)
        {
            recordStream.Seek(groupRef.DataOffset, SeekOrigin.Begin);
            byte[] bytes = new byte[groupRef.GroupHeader.DataSize];
            await recordStream.ReadAsync(bytes);

            return(RecordParser.Parse(bytes, 0, bytes.Length, groupRef.DataOffset));
        }
Beispiel #2
0
        public async Task <GroupSet> ReadToSet(Result.GroupRef groupRef, int depth)
        {
            var result = await recordReader.ReadGroup(groupRef);

            return(new GroupSet()
            {
                header = groupRef.GroupHeader,
                records = result.records,
                groups = depth > 0 ? await result.groupRefs.ToAsyncEnumerable().SelectAwait(async r => await ReadToSet(r, depth - 1)).ToListAsync() : new List <GroupSet>(),
            });
        }
Beispiel #3
0
        public async Task <Result> Read(long offset, long length)
        {
            recordStream.Seek(offset, SeekOrigin.Begin);
            var result = new Result()
            {
                records   = new List <Record.RecordHeader>(),
                groupRefs = new List <Result.GroupRef>()
            };
            long end = offset + length;

            byte[] bytes = new byte[24];
            while (recordStream.Position < end)
            {
                await recordStream.ReadAsync(bytes, 0, 24);

                string type = Encoding.UTF8.GetString(bytes, 0, 4);

                switch (type)
                {
                case "GRUP":
                    var groupHeader = Group.GroupHeader.Parse(bytes);
                    var groupRef    = new Result.GroupRef()
                    {
                        GroupHeader = groupHeader,
                        DataOffset  = recordStream.Position
                    };
                    result.groupRefs.Add(groupRef);
                    // Skip past the records in the group
                    recordStream.Seek(groupHeader.DataSize, SeekOrigin.Current);
                    break;

                default:
                    var recordHeader = Record.RecordHeader.Parse(bytes);
                    result.records.Add(recordHeader);
                    // SKip past the fields in the record
                    recordStream.Seek(recordHeader.DataSize, SeekOrigin.Current);
                    break;
                }
            }
            return(result);
        }
Beispiel #4
0
 public async Task <Result> ReadGroup(Result.GroupRef groupRef)
 {
     return(await Read(groupRef.DataOffset, groupRef.GroupHeader.DataSize));
 }