type="common":單值字段,同前文。type="list":數組/列表字段。size:元素個數上限。ref:引用 ListDataDef 定義元素結構。key → {offset, type, listMeta}。type="list",取 ref 查二級映射表(ListDataDef 同構)。size * 元素大小。基址 + 列表offset + index * 元素大小 + 字段offset。// 獲取列表上下文(含基址、二級映射指針、size等)
int getDataList(const void* addr, const char* key, struct DataList* outList);
// 列表內元素字段讀寫
int getDataInList(const void* addr, const DataList* list, int idx,
const char* fieldKey, int bufLen, char* value);
int putDataInList(void* addr, const DataList* list, int idx,
const char* fieldKey, const char* value);
DataList 結構體封裝:baseOffset, elementSize, count, subMap*。
cardNo [19] @ 0 amount [13] @ 20 tradeDate [8] @ 36 tradeTime [6] @ 48 listData [3 * 48 = 144] @ 52 (假設對齊後 myListData 元素=48) ├─[0] listData1[19] listData2[13] listData3[8] listData4[6] ├─[1] ... └─[2] ... 總大小 = 52 + 144 = 196 字節
libxml2/expat/tinyxml 解析 XML,構建映射表結構體數組。idx >= size、fieldKey 不存在、長度超限 統一返回錯誤碼。version 屬性,啟動時校驗;新字段默認值 0/空串,舊數據自動兼容。