private Folder ReadFolder(HeaderBuffer headerBytes) { Folder folder = new Folder(this); folder.Coders = headerBytes.CreateArray<CodersInfo>(); int numInStreams = 0; int numOutStreams = 0; foreach (var coder in folder.Coders) { byte mainByte = headerBytes.ReadByte(); int size = (byte)(mainByte & 0xF); coder.Method = headerBytes.ReadBytes(size); if ((mainByte & 0x10) != 0) { coder.NumberOfInStreams = headerBytes.ReadEncodedInt64(); coder.NumberOfOutStreams = headerBytes.ReadEncodedInt64(); } else { coder.NumberOfInStreams = 1; coder.NumberOfOutStreams = 1; } if ((mainByte & 0x20) != 0) { ulong propertiesSize = headerBytes.ReadEncodedInt64(); coder.Properties = headerBytes.ReadBytes((int)propertiesSize); } while ((mainByte & 0x80) != 0) { mainByte = headerBytes.ReadByte(); headerBytes.ReadBytes(mainByte & 0xF); if ((mainByte & 0x10) != 0) { headerBytes.ReadEncodedInt64(); headerBytes.ReadEncodedInt64(); } if ((mainByte & 0x20) != 0) { ulong propertiesSize = headerBytes.ReadEncodedInt64(); headerBytes.ReadBytes((int)propertiesSize); } } numInStreams += (int)coder.NumberOfInStreams; numOutStreams += (int)coder.NumberOfOutStreams; } int numBindPairs = numOutStreams - 1; folder.BindPairs = new BindPair[numBindPairs]; for (int i = 0; i < numBindPairs; i++) { BindPair bindpair = new BindPair(); folder.BindPairs[i] = bindpair; bindpair.InIndex = headerBytes.ReadEncodedInt64(); bindpair.OutIndex = headerBytes.ReadEncodedInt64(); } int numPackedStreams = numInStreams - numBindPairs; folder.PackedStreamIndices = new ulong[numPackedStreams]; if (numPackedStreams == 1) { uint pi = 0; for (uint j = 0; j < numInStreams; j++) { if (!folder.BindPairs.Where(x => x.InIndex == j).Any()) { folder.PackedStreamIndices[pi++] = j; break; } } } else { for (uint i = 0; i < numPackedStreams; i++) { folder.PackedStreamIndices[i] = headerBytes.ReadEncodedInt64(); } } return folder; }
private Folder ReadFolder(HeaderBuffer headerBytes) { Folder folder = new Folder(this); folder.Coders = headerBytes.CreateArray <CodersInfo>(); int numInStreams = 0; int numOutStreams = 0; foreach (var coder in folder.Coders) { byte mainByte = headerBytes.ReadByte(); int size = (byte)(mainByte & 0xF); coder.Method = headerBytes.ReadBytes(size); if ((mainByte & 0x10) != 0) { coder.NumberOfInStreams = headerBytes.ReadEncodedInt64(); coder.NumberOfOutStreams = headerBytes.ReadEncodedInt64(); } else { coder.NumberOfInStreams = 1; coder.NumberOfOutStreams = 1; } if ((mainByte & 0x20) != 0) { ulong propertiesSize = headerBytes.ReadEncodedInt64(); coder.Properties = headerBytes.ReadBytes((int)propertiesSize); } while ((mainByte & 0x80) != 0) { mainByte = headerBytes.ReadByte(); headerBytes.ReadBytes(mainByte & 0xF); if ((mainByte & 0x10) != 0) { headerBytes.ReadEncodedInt64(); headerBytes.ReadEncodedInt64(); } if ((mainByte & 0x20) != 0) { ulong propertiesSize = headerBytes.ReadEncodedInt64(); headerBytes.ReadBytes((int)propertiesSize); } } numInStreams += (int)coder.NumberOfInStreams; numOutStreams += (int)coder.NumberOfOutStreams; } int numBindPairs = numOutStreams - 1; folder.BindPairs = new BindPair[numBindPairs]; for (int i = 0; i < numBindPairs; i++) { BindPair bindpair = new BindPair(); folder.BindPairs[i] = bindpair; bindpair.InIndex = headerBytes.ReadEncodedInt64(); bindpair.OutIndex = headerBytes.ReadEncodedInt64(); } int numPackedStreams = numInStreams - numBindPairs; folder.PackedStreamIndices = new ulong[numPackedStreams]; if (numPackedStreams == 1) { uint pi = 0; for (uint j = 0; j < numInStreams; j++) { if (!folder.BindPairs.Where(x => x.InIndex == j).Any()) { folder.PackedStreamIndices[pi++] = j; break; } } } else { for (uint i = 0; i < numPackedStreams; i++) { folder.PackedStreamIndices[i] = headerBytes.ReadEncodedInt64(); } } return(folder); }