3,881
社区成员
发帖
与我相关
我的任务
分享参考 TLV / XDR 之类的格式。给一个最简单的 TLV 的例子。
FILE *fp = fopen("config.dat", "wb");
typedef enum { INT_TYPE, STRING_TYPE, } type_t;
void write_tlv(FILE *fp, int type, int length, void *value) {
fwrite(fp, &type, sizeof(type));
fwrite(fp, &length, sizeof(length));
fwrite(fp, value, length);
}
int arg_1 = 1;
write_tlv(fp, INT_TYPE, sizeof(arg_1), &arg_1);