Ejemplo n.º 1
0
    def __init__(self, f, wdb_parser):
        self._data_class = getattr(dbc.data,
                                   wdb_parser.class_name().replace('-', '_'))
        self._parser = f.parser
        self._wdb_parser = wdb_parser
        self._records = f.parser.n_entries(wdb_parser)

        self._key_field_name = dbc.use_hotfix_key_field(
            self._wdb_parser.class_name())
        if self._key_field_name:
            self._key_field_index = self._data_class._cd[self._key_field_name]

        self._record = 0
Ejemplo n.º 2
0
    def build_decoder(self):
        struct_columns = []
        bitpack_columns = []

        decoders = []

        for column_idx in range(0, self.parser().n_fields()):
            column = self.parser().column(column_idx)

            # Hotfixed columns always have inlined strings
            if column.is_string() and (self.parser().has_offset_map() or self._cache):
                if len(struct_columns) > 0:
                    decoders.append(WDC1StructSegmentParser(self, struct_columns))
                    struct_columns = []

                decoders.append(WDC1StringSegmentParser(self, column))

            # Presume that bitpack is a continious segment that runs to the end of the record
            elif column.size_type() == WDC1_SPECIAL_COLUMN:
                # Bit-packed data (special columns) seem to be expanded for cache files
                if self._cache:
                    struct_columns.append(column)
                else:
                    bitpack_columns.append(column)
            else:
                struct_columns.append(column)

        # Build decoders when all columns are looped in
        if len(struct_columns) > 0:
            decoders.append(WDC1StructSegmentParser(self, struct_columns))

        # Presume the record ends with a bit-packed set of columns
        if len(bitpack_columns) > 0:
            decoders.append(WDC1PackedBitSegmentParser(self, bitpack_columns))

        # Grab the key block id from the end of the hotfix record, if this
        # hotfix entry is not for one of the client data files where the data
        # is already incorporated into the record itself
        if self._cache and self.parser().has_key_block() and \
                not dbc.use_hotfix_key_field(self.parser().class_name()):
            decoders.append(WDC1HotfixKeyBlockParser(self, self.parser().key_bytes()))

        self._decoders = decoders