daeken_bb
06-05-2005, 08:31 PM
This is a proposition for a meta-language for networking. This would provide us with a way to build packet parsers with little to no hassle. These can be compiled to C code (which would be a struct, or series of structs, and a function that builds the packet or reads the data into a usable struct) or can be loaded/modified on the fly for development.
Syntax:
struct struct_name (optional size) {
type item_name;
type item_name = default_value;
type item_name = 's'; // This works as in C.
type item_name[count];
type item_name[count] = {5, 6, 7, 8};
type item_name[count] = 'non-terminated string';
type item_name[count] = "null-terminated string";
struct struct_name item_name;
struct struct_name item_name[count];
};
You can also use a map structure to rename items without actually changing their name, this is useful for keeping structures named as they are elsewhere, while keeping compatibility with existing code.
You can use struct items as the count for an array, unlike in C. However, this means it can not be translated to a single array, and must be processed separately. This should not be any more of a performance hit than doing it by hand.
Maps are defined as such:
struct ... {
...
} map {
Access_Name: name_in_struct;
};
Examples:
A simple struct and map.
struct NameApproval (76) {
char name[64]; /* 00000000 */
uint32 race; /* 00000064 */
uint32 class; /* 00000068 */
uint32 deity; /* 00000072 */
} map {
Name: name;
Race: race;
Class_: class;
Deity: deity;
};
A dynamic length string.
struct DynamicLength {
uint32 length;
char name[length];
};
Any input would be welcome.
Thanks,
Lord Daeken M. BlackBlade
(Cody Brocious)
Syntax:
struct struct_name (optional size) {
type item_name;
type item_name = default_value;
type item_name = 's'; // This works as in C.
type item_name[count];
type item_name[count] = {5, 6, 7, 8};
type item_name[count] = 'non-terminated string';
type item_name[count] = "null-terminated string";
struct struct_name item_name;
struct struct_name item_name[count];
};
You can also use a map structure to rename items without actually changing their name, this is useful for keeping structures named as they are elsewhere, while keeping compatibility with existing code.
You can use struct items as the count for an array, unlike in C. However, this means it can not be translated to a single array, and must be processed separately. This should not be any more of a performance hit than doing it by hand.
Maps are defined as such:
struct ... {
...
} map {
Access_Name: name_in_struct;
};
Examples:
A simple struct and map.
struct NameApproval (76) {
char name[64]; /* 00000000 */
uint32 race; /* 00000064 */
uint32 class; /* 00000068 */
uint32 deity; /* 00000072 */
} map {
Name: name;
Race: race;
Class_: class;
Deity: deity;
};
A dynamic length string.
struct DynamicLength {
uint32 length;
char name[length];
};
Any input would be welcome.
Thanks,
Lord Daeken M. BlackBlade
(Cody Brocious)