$npx -y skills add easyzoom/aix-skills --skill embedded-data-parsing-libsUse when integrating, porting, configuring, or debugging embedded C data parsers such as cJSON, jsmn, or inih on MCU projects
| 1 | # Embedded Data Parsing Libs |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill for small embedded data parsers where the main risks are memory allocation, input bounds, encoding assumptions, recursion, and callback handling. Cover `cJSON`, `jsmn`, and `inih` without copying their full APIs. |
| 6 | |
| 7 | ## When To Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - The user wants to parse JSON or INI on an MCU. |
| 12 | - The task mentions `cJSON`, `jsmn`, `inih`, config files, telemetry JSON, command payloads, or settings parsing. |
| 13 | - The issue involves parse failure, memory leak, heap exhaustion, malformed input, callback mapping, or stack/recursion limits. |
| 14 | |
| 15 | Do not use this skill for binary protocols or large streaming parsers outside these small libraries. |
| 16 | |
| 17 | ## First Questions |
| 18 | |
| 19 | Ask for: |
| 20 | |
| 21 | - Parser library: `cJSON`, `jsmn`, `inih`, or another small C parser. |
| 22 | - Input source and maximum input size. |
| 23 | - Runtime: bare metal, RTOS, Linux, bootloader, or shell command. |
| 24 | - Whether dynamic allocation is allowed. |
| 25 | - Expected schema and how malformed input should behave. |
| 26 | - Current error, sample input, and memory budget. |
| 27 | |
| 28 | ## Library Checks |
| 29 | |
| 30 | ### cJSON |
| 31 | |
| 32 | - Decide whether heap allocation is acceptable. |
| 33 | - Provide custom malloc/free hooks if the project uses a custom allocator. |
| 34 | - Always delete parsed trees after use. |
| 35 | - Bound input size before parsing. |
| 36 | - Validate type before reading values. |
| 37 | |
| 38 | ### jsmn |
| 39 | |
| 40 | - Allocate enough tokens for the expected JSON shape. |
| 41 | - Handle `JSMN_ERROR_NOMEM`, `JSMN_ERROR_INVAL`, and `JSMN_ERROR_PART`. |
| 42 | - Remember that tokens reference the original input buffer. |
| 43 | - Validate string lengths and value types manually. |
| 44 | |
| 45 | ### inih |
| 46 | |
| 47 | - Implement the handler callback with strict section/key matching. |
| 48 | - Decide whether duplicate keys overwrite, error, or merge. |
| 49 | - Bound line length and input source. |
| 50 | - Validate converted numeric values and ranges. |
| 51 | |
| 52 | ## Common Failures |
| 53 | |
| 54 | - Heap fragmentation from repeated `cJSON_Parse` without hooks or cleanup. |
| 55 | - Token buffer too small for `jsmn`. |
| 56 | - Using JSON token pointers after the input buffer is freed. |
| 57 | - Accepting partial config and booting with unsafe defaults. |
| 58 | - Silent typo in INI key because handler ignores unknown fields. |
| 59 | |
| 60 | ## Verification |
| 61 | |
| 62 | Before claiming parser integration works: |
| 63 | |
| 64 | - State parser, allocation policy, max input size, and schema assumptions. |
| 65 | - Test valid input, missing fields, wrong types, malformed input, and oversize input. |
| 66 | - Confirm memory is released or static buffers are bounded. |
| 67 | - Confirm unknown fields and duplicate keys behavior. |
| 68 | |
| 69 | ## Example |
| 70 | |
| 71 | User: |
| 72 | |
| 73 | ```text |
| 74 | 想用 cJSON 解析串口发来的配置。 |
| 75 | ``` |
| 76 | |
| 77 | Agent: |
| 78 | |
| 79 | 1. Asks for max payload size, schema, allocator policy, and malformed-input behavior. |
| 80 | 1. Uses custom hooks if needed and validates each field type. |
| 81 | 1. Tests good JSON, missing keys, bad types, and oversized payloads. |