/* * internal UInt32 ReadEncodedInt() * { * byte first = B.ReadByte(); * if ((first & 0x80) == 0) * return first; * byte second = B.ReadByte(); * if ((first & 0xC0) == 0x80) * return ((uint)(first & 0x7F)) << 8 | second; * else if ((first & 0xE0) == 0xC0) * { * byte third = B.ReadByte(); * byte fourth = B.ReadByte(); * return ((uint)(first & 0x1F) << 24) | ((uint)second) << 16 | ((uint)third) << 8 | (uint)fourth; * } * else * throw new BadImageFormatException(Res.InvalidCompressedInt); * } */ internal MetadataToken ReadMetadataToken(Encodings E) { UInt32 Code = (MetadataTokenSize(E) == 2) ? B.ReadUInt16() : B.ReadUInt32(); MetadataToken Result; EncodingDesc Desc = EncodingDescs[(Int32)E]; Tables[] Ts = Desc.WhichTables; UInt32 Mask = (1U << Desc.TagBits) - 1; Result.Table = Ts[Code & Mask]; Result.Index = Code >> Desc.TagBits; if (Result.Table == Tables.Invalid) { throw new BadImageFormatException(Res.InvalidMetadataTokenNilTable); } return(Result); }
UInt32 MetadataTokenSize(Encodings Which) { EncodingDesc E = EncodingDescs[(int)Which]; int TagBits = E.TagBits; UInt32 MaxRows = 0; foreach (Tables Table in E.WhichTables) { if (Table == Tables.Invalid) { continue; } UInt32 N = NRows[(int)Table]; if (N > MaxRows) { MaxRows = N; } } return((MaxRows < (1 << (16 - TagBits))) ? 2U : 4U); }