Skip to main content
1 of 2

Table key smaller than 64bit

Here is my some code. To reduce the data size, 'id', 'knight', and 'sale_id' are not uint64_t, even though they are keys. Because 'primary_key()', 'by_knight()' and 'by_saleid()' functions convert key to uint64_t.

It works, but I wonder if it can be used like this.

//@abi table item i64
struct item {
    uint16_t id = 0;
    uint16_t code = 0;
    uint8_t knight = 0;
    uint8_t level = 0;
    uint8_t exp = 0;
    uint32_t dna = 0;
    uint32_t saleid = 0;

    uint64_t primary_key() const {
        return id;
    }

    uint64_t by_knight() const {
        return knight;
    }

    uint64_t by_saleid() const {
        return saleid;
    }

    EOSLIB_SERIALIZE(
            item,
            (id)
            (code)
            (knight)
            (level)
            (exp)
            (dna)
            (saleid)
    )
};

typedef eosio::multi_index< N(item), item,
    indexed_by< N(knight), const_mem_fun<item, uint64_t, &item::by_knight> >,
    indexed_by< N(saleid), const_mem_fun<item, uint64_t, &item::by_saleid> >
> item_table;