# Packet Definition Parser Fast XML-like parser for binary packet structures with versioning and conditional fields. ## Basic Syntax ```xml ``` ## Field Types | Type | Size | Description | |------|------|-------------| | `i8`, `i16`, `i32`, `i64` | 1-8 bytes | Unsigned integers | | `si8`, `si16`, `si32`, `si64` | 1-8 bytes | Signed integers | | `f32`, `f64`, `double` | 4-8 bytes | Floating point | | `str8`, `str16`, `str32` | Variable | Length-prefixed strings | | `char` | Fixed | Fixed-size byte array | | `color` | 3 bytes | RGB color (r,g,b) | | `equip` | 8 bytes | Equipment item | | `array` | Variable | Array of substructures | ## Multiple Field Names ```xml ``` ## Conditional Fields ```xml ``` ### Condition Types **Flag Conditions:** - `flag:name` - Flag is set - `!flag:name` - Flag not set **Variable Conditions:** - `var:name` - Variable exists and is non-zero - `!var:name` - Variable doesn't exist or is zero **Version Conditions:** - `version>=562` - Version comparisons - `version<1200` - Supports `>=`, `<=`, `>`, `<` **Value Comparisons:** - `field>=value` - Numeric comparisons - `field!=0` - Supports `>=`, `<=`, `>`, `<`, `==`, `!=` **String Length:** - `name!>5` - String longer than 5 chars - `name!<=100` - String 100 chars or less - Supports `!>`, `!<`, `!>=`, `!<=`, `!=` **Bitwise Operations:** - `field&0x01` - Bitwise AND with hex value **Complex Logic:** - `cond1,cond2` - OR logic (comma-separated) - `cond1&cond2` - AND logic (ampersand) - `version>=562&level>10` - Multiple conditions **Array Context:** - `item_type_%i!=0` - `%i` substitutes current array index ## Groups Organize related fields with automatic prefixing: ```xml ``` ## Arrays ```xml ``` ## Advanced Field Attributes ### Type Switching ```xml ``` ### Oversized Fields ```xml ``` ### Field Modifiers ```xml ``` ## Complete Attribute Reference | Attribute | Description | Example | |-----------|-------------|---------| | `name` | Field name(s), comma-separated | `"id,account_id"` | | `if` | Conditional parsing expression | `"flag:has_guild"` | | `size` | Fixed array size for `char` type | `"10"` | | `count` | Array size variable | `"var:item_count"` | | `substruct` | Reference to substruct | `"ItemInfo"` | | `oversized` | Threshold for oversized handling | `"255"` | | `type2` | Alternative field type | `"f32"` | | `type2_if` | Condition for using type2 | `"stat_type!=6"` | | `default` | Default value for initialization | `"0"` | | `max_size` | Maximum array size limit | `"100"` | | `optional` | Field is optional | `"true"` | | `add_to_struct` | Include in packet structure | `"false"` | | `add_type` | Type when adding to packet | `"i16"` | ## Reusable Substructs ```xml ``` ## Multiple Versions ```xml ``` ## Comments ```xml ``` ## Usage ```go import "eq2emu/internal/parser" // Parse PML content packets, err := parser.Parse(pmlContent) if err != nil { log.Fatal(err) } // Get packet definition packet := packets["PacketName"] // Parse binary data with version and flags result, err := packet.Parse(data, version, flags) if err != nil { log.Fatal(err) } // Access parsed fields playerID := result["player_id"].(uint32) playerName := result["player_name"].(common.EQ2String16).Data ``` ## Complete Example ```xml ```