keichi / binary-parser

A blazing-fast declarative parser builder for binary data
MIT License
865 stars 134 forks source link

What's the problem with this conversion #154

Closed aleffff closed 4 years ago

aleffff commented 4 years ago

I have a binary file, in the following structure in C ++

struct STRUCT_MOB
{
    char           MobName[NAME_LENGTH];      // The name of the mob
    char           Clan;          // The clan the mob belongs to
    unsigned char  Merchant;      // The mob's merchant ID
    unsigned short Guild;         // The ID of the guild the mob belongs to
    unsigned char  Class;         // The mobs class
    unsigned short  Rsv;
    unsigned char Quest;

    int            Coin;          // The ammount of coins the mob has

    long long   Exp;              // The ammount of experience the mob has to level up

    short          SPX;          // The Y position saved by the stellar gem, to teleport the mob there when using warp scroll
    short          SPY;          // The Y position saved by the stellar gem, to teleport the mob there when using warp scroll

}

When I use binary parse

.array('mob', {

      //unsigned não pode ser negativo.
      type: Parser.start()
        .string('MobName', {stripNull: true, length: 16}) //char
        .int8('Clan') //char 1byte
        .uint8('Merchant') //unsigned char 1 byte
        .int16('Guild') // unsigned short 2 byte
        .uint8('Class') //unsigned char 1 byte
        .uint16('Rsv') //unsigned short 2 byte
        .uint8('Quest') //unsigned char 1 byte

        .int32('coin') //int 4 Bytes

        .int64('exp') //long long 8 Bytes

        .int16('SPX') //short 2 Bytes
        .int16('SPY') //short 2 Bytes
});

Conversion doesn't match reality, why?

keichi commented 4 years ago

Your C++ code is defining a struct while the binary-parser code is defining a parser to parse an array of structs. Are you trying to parse an array or a single struct? In addition, length/lengthInBytes/readUntil option seems to be missing.

keichi commented 4 years ago

Closing for inactivity. Please reopen if your problem still persists.