Forum > Software Development

Understanding the DBC Format

<< < (2/6) > >>

schlumpf:
I updated the wiki article to be more clear. See http://pxr.dk/wowdev/wiki/index.php?title=Category:DBC.

You might want to change

--- Code: ---NSData    *recordCountData = [data subdataWithRange:NSMakeRange(4, 8)];
NSNumber    *recordCount     = [NSNumber numberWithInt:*(int*)([recordCountData bytes])];
--- End code ---
to

--- Code: ---NSNumber* recordCount = [NSNumber numberWithInt:*(int*)([data bytes] + 4)];
--- End code ---

In your case, you might want to use the second (offset based) variant in Objective-C. NSString's stringWithUTF8String: should be used.

--- Code: ---NSString* name = [NSString stringWithUTF8String:([data bytes] + calculated_offset)];
--- End code ---

iindigo:
The update is quite helpful, thanks.

This confuses me, though:

--- Code: ---NSString* name = [NSString stringWithUTF8String:([data bytes] + calculated_offset)];
--- End code ---

What is this a parallel to in the C++? Also, should I be using structs in Obj-C? I know it supports them but I've had no need for them up until this point.

schlumpf:

--- Quote from: "iindigo" ---This confuses me, though:

--- Code: ---NSString* name = [NSString stringWithUTF8String:([data bytes] + calculated_offset)];
--- End code ---

--- End quote ---

--- Code: ---// const char* file;
// const char* records;
uint32_t record_count = *(uint32_t*) (file + 1 * sizeof (uint32_t));
uint32_t record_size = *(uint32_t*) (file + 3 * sizeof (uint32_t));
uint32_t string_block_offset = 5 * sizeof (uint32_t) + record_size * record_count;
uint32_t string_offset = *(uint32_t*)(records + i * record_size + sizeof (uint32_t) /* name */);
uint32_t calculated_offset = string_block_offset + string_offset;
printf ("record %u: %u, %sn", *(uint32_t*)(records + i * record_size /* id */), file + calculated_offset);
--- End code ---


--- Quote from: "iindigo" ---Also, should I be using structs in Obj-C? I know it supports them but I've had no need for them up until this point.
--- End quote ---
That would be personal preference. It might be easier using them, as you can just take [data bytes] once, cast it to dbc_file<T> and you're done. This does assume you know T though. Else, there isn't that much benefit.

You may want to take

--- Code: ---NSData* string_block = [data subdataWithRange:NSMakeRange(string_block_offset, [data count])];
--- End code ---
though. Then, you will just have to take

--- Code: ---[NSString stringWithUTF8String:([string_block bytes] + string_offset)];
--- End code ---

iindigo:
Recently I've had the time to pick this up and start tinkering with it again and the situation hasn't changed much from what it was before. I still feel like an idiot swinging around in the dark because of bits and pieces I don't understand.


--- Quote ---
--- Code: ---// const char* file;
// const char* records;
uint32_t record_count = *(uint32_t*) (file + 1 * sizeof (uint32_t));
uint32_t record_size = *(uint32_t*) (file + 3 * sizeof (uint32_t));
uint32_t string_block_offset = 5 * sizeof (uint32_t) + record_size * record_count;
uint32_t string_offset = *(uint32_t*)(records + i * record_size + sizeof (uint32_t) /* name */);
uint32_t calculated_offset = string_block_offset + string_offset;
printf ("record %u: %u, %sn", *(uint32_t*)(records + i * record_size /* id */), file + calculated_offset);
--- End code ---

--- End quote ---
In this, what is records? Is it the same as what's listed in the wiki entry, i.e.

--- Code: ---const char* records = file + 5 * sizeof (uint32_t) /* header */;
--- End code ---
? What is its role in calculating the string offset?

Also, do values of 264, 35924, and 43533 sound right for record size, string block offset, and length of the file in bytes? The DBC file I'm testing with is attached.

schlumpf:
Records is a pointer to the individual rows of the database, as described in the specific table documentation. Records start behind the header, so yes, it is file + 5*sizeof uint32
The string block starts behind the records, thus is at records + record_count * record_size.
Numbers seem fine, if there are about 66 columns and 136 rows.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version