$npx -y skills add easyzoom/aix-skills --skill nanopb-integrationUse when integrating, porting, configuring, or debugging nanopb Protocol Buffers, .proto generation, pb_encode, pb_decode, callbacks, fixed sizes, or embedded serialization
| 1 | # nanopb Integration |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill to integrate nanopb by controlling schema size, generated options, callbacks, and buffer ownership. Embedded protobuf failures usually come from mismatched generated files, unbounded fields, or callback misuse. |
| 6 | |
| 7 | ## When To Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - The user wants Protocol Buffers on an MCU using nanopb. |
| 12 | - The task involves `.proto`, `.options`, `nanopb_generator.py`, `pb_encode`, `pb_decode`, repeated fields, strings, bytes, callbacks, or fixed-size arrays. |
| 13 | - Encoding/decoding fails, messages are truncated, memory usage is too high, or host and device schemas mismatch. |
| 14 | |
| 15 | Do not use this skill for general JSON/INI parsing. Use `embedded-data-parsing-libs` instead. |
| 16 | |
| 17 | ## First Questions |
| 18 | |
| 19 | Ask for: |
| 20 | |
| 21 | - nanopb version and how code generation runs. |
| 22 | - `.proto`, `.options`, generated `.pb.c/.pb.h`, and host-side schema version. |
| 23 | - Transport/storage where messages are sent. |
| 24 | - Max message size, RAM budget, and whether streaming decode is needed. |
| 25 | - Current encode/decode error and sample payload if available. |
| 26 | |
| 27 | ## Integration Checklist |
| 28 | |
| 29 | 1. Lock schema and generated files together. |
| 30 | Regenerate `.pb.c/.pb.h` whenever `.proto` or `.options` changes. |
| 31 | |
| 32 | 1. Bound variable fields. |
| 33 | Use nanopb options for max string, bytes, repeated field, or callback-based streaming. |
| 34 | |
| 35 | 1. Size buffers explicitly. |
| 36 | Know max encoded size and transport frame limits. |
| 37 | |
| 38 | 1. Check return values. |
| 39 | Always inspect `pb_encode`/`pb_decode` failure and error text. |
| 40 | |
| 41 | 1. Validate compatibility. |
| 42 | Test device-generated payload with host decoder and host-generated payload with device decoder. |
| 43 | |
| 44 | ## Common Failures |
| 45 | |
| 46 | - Generated files are stale relative to `.proto`. |
| 47 | - Repeated/string fields need max sizes but default to callbacks. |
| 48 | - Decode fails because the transport strips length framing. |
| 49 | - Device and host use different schema versions. |
| 50 | - Stack buffers are too small for worst-case message size. |
| 51 | - Callback decode stores pointers into temporary buffers. |
| 52 | |
| 53 | ## Verification |
| 54 | |
| 55 | Before claiming nanopb works: |
| 56 | |
| 57 | - State schema version, generator path, max message size, and field-size policy. |
| 58 | - Confirm encode and decode of a golden message. |
| 59 | - Confirm malformed/truncated payload behavior. |
| 60 | - Confirm host-device compatibility. |
| 61 | - Confirm memory usage fits stack/heap/static budget. |
| 62 | |
| 63 | ## Example |
| 64 | |
| 65 | User: |
| 66 | |
| 67 | ```text |
| 68 | nanopb 解码一直失败,但 PC 端 protobuf 能解析。 |
| 69 | ``` |
| 70 | |
| 71 | Agent: |
| 72 | |
| 73 | 1. Asks for `.proto`, `.options`, generated files, payload framing, and error string. |
| 74 | 1. Checks stale generation and max field settings. |
| 75 | 1. Tests a golden payload both directions. |