<commit_before>
use std::io::{Read, Seek, Result};
use std::collections::HashMap;
use enum_primitive::FromPrimitive;
use byteorder::{ReadBytesExt, LittleEndian};

use utils::stream::*;
use metadata::heap::{StringHeap, UserStringHeap, UserString};
use loader::tables::{ModuleEntry, TableEntryReader};

#[derive(Debug, Clone)]
pub struct StreamHeader {
  pub offset: u32,
  pub size: u32,
  pub name: String
}

impl ReadableStruct for StreamHeader {
  fn read_from<R: Read + Seek>(reader: &mut R) -> Result<StreamHeader> {
    let offset = reader.read_u32::<LittleEndian>()?;
    let size = reader.read_u32::<LittleEndian>()?;
    let name = reader.read_c_str_aligned(4)?;

    Ok(StreamHeader { offset, size, name })
  }
}

/// The #~ stream.
#[derive(Debug, Clone)]
pub struct MetaDataTablesStream {

}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum IndexSize {
  Word,
  Dword
}

impl IndexSize {
  pub fn to_u32(self) -> u32 {
    match self {
      IndexSize::Word => u16::max_value() as u32,
      IndexSize::Dword => u32::max_value()
    }
  }
}

impl From<bool> for IndexSize {
  fn from(x: bool) -> IndexSize {
    if x {IndexSize::Dword} else {IndexSize::Word} 
  }
}

#[derive(Debug)]
pub struct HeapOffsetSizes {
  pub string_index: IndexSize,
  pub guid_index: IndexSize,
  pub blob_index: IndexSize
}

enum_from_primitive! {
  #[derive(Hash, PartialEq, Eq, Debug, Copy, Clone)]
  pub enum TableId {
    Module                  = 00,
    Field                   = 04,
    InterfaceImpl           = 09,
    CustomAttribute         = 12,
    ClassLayout             = 15,
    EventMap                = 18,
    Property                = 23,
    ModuleRef               = 26,
    FieldRVA                = 29,
    AssemblyOS              = 34,
    AssemblyRefOS           = 37,
    ManifestResource        = 40,
    GenericParamConstraint  = 44,
    TypeRef                 = 01,
    TypeDef                 = 02,
    MethodDef               = 06,
    Param                   = 08,
    MemberRef               = 10,
    Constant                = 11,
    FieldMarshal            = 13,
    DeclSecurity            = 14,
    FieldLayout             = 16,
    StandAloneSig           = 17,
    Event                   = 20,
    PropertyMap             = 21,
    MethodSemantics         = 24,
    MethodImpl              = 25,
    TypeSpec                = 27,
    ImplMap                 = 28,
    Assembly                = 32,
    AssemblyProcessor       = 33,
    AssemblyRef             = 35,
    AssemblyRefProcessor    = 36,
    File                    = 38,
    ExportedType            = 39,
    NestedClass             = 41,
    GenericParam            = 42
  }
}

#[derive(Debug)]
pub struct TableIds(Vec<TableId>);

impl From<u64> for TableIds {
  fn from(x: u64) -> TableIds {
    let mut table_ids = vec![];
<commit_msg>Add a missing table id, reorder them<commit_after>
use std::io::{Read, Seek, Result};
use std::collections::HashMap;
use enum_primitive::FromPrimitive;
use byteorder::{ReadBytesExt, LittleEndian};

use utils::stream::*;
use metadata::heap::{StringHeap, UserStringHeap, UserString};
use loader::tables::{ModuleEntry, TableEntryReader};

#[derive(Debug, Clone)]
pub struct StreamHeader {
  pub offset: u32,
  pub size: u32,
  pub name: String
}

impl ReadableStruct for StreamHeader {
  fn read_from<R: Read + Seek>(reader: &mut R) -> Result<StreamHeader> {
    let offset = reader.read_u32::<LittleEndian>()?;
    let size = reader.read_u32::<LittleEndian>()?;
    let name = reader.read_c_str_aligned(4)?;

    Ok(StreamHeader { offset, size, name })
  }
}

/// The #~ stream.
#[derive(Debug, Clone)]
pub struct MetaDataTablesStream {

}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum IndexSize {
  Word,
  Dword
}

impl IndexSize {
  pub fn to_u32(self) -> u32 {
    match self {
      IndexSize::Word => u16::max_value() as u32,
      IndexSize::Dword => u32::max_value()
    }
  }
}

impl From<bool> for IndexSize {
  fn from(x: bool) -> IndexSize {
    if x {IndexSize::Dword} else {IndexSize::Word} 
  }
}

#[derive(Debug)]
pub struct HeapOffsetSizes {
  pub string_index: IndexSize,
  pub guid_index: IndexSize,
  pub blob_index: IndexSize
}

enum_from_primitive! {
  #[derive(Hash, PartialEq, Eq, Debug, Copy, Clone)]
  pub enum TableId {
    Module                  = 00,
    TypeRef                 = 01,
    TypeDef                 = 02,
    Field                   = 04,
    MethodDef               = 06,
    Param                   = 08,
    InterfaceImpl           = 09,
    MemberRef               = 10,
    Constant                = 11,
    CustomAttribute         = 12,
    FieldMarshal            = 13,
    DeclSecurity            = 14,
    ClassLayout             = 15,
    FieldLayout             = 16,
    StandAloneSig           = 17,
    EventMap                = 18,
    Event                   = 20,
    PropertyMap             = 21,
    Property                = 23,
    MethodSemantics         = 24,
    MethodImpl              = 25,
    ModuleRef               = 26,
    TypeSpec                = 27,
    ImplMap                 = 28,
    FieldRVA                = 29,
    Assembly                = 32,
    AssemblyProcessor       = 33,
    AssemblyOS              = 34,
    AssemblyRef             = 35,
    AssemblyRefProcessor    = 36,
    AssemblyRefOS           = 37,
    File                    = 38,
    ExportedType            = 39,
    ManifestResource        = 40,
    NestedClass             = 41,
    GenericParam            = 42,
    MethodSpec              = 43,
    GenericParamConstraint  = 44
  }
}

#[derive(Debug)]
pub struct TableIds(Vec<TableId>);

impl From<u64> for TableIds {
  fn from(x: u64) -> TableIds {
    let mut table_ids = vec![];

{'fraction_non_alphanumeric': 0.10718614718614719, 'fraction_numerical': 0.03393939393939394, 'mean_word_length': 1.810705596107056, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3669633', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1782, 'n_words': 444}